#include "stdafx.h" #include <stdio.h> #include <string.h> #include <conio.h> #include <Windows.h> char shellcode[] = "x31xd2xb2x30x64x8bx12x8bx52x0cx8bx52x1cx8bx42" "x08x8bx72x20x8bx12x80x7ex0cx33x75xf2x89xc7x03" "x78x3cx8bx57x78x01xc2x8bx7ax20x01xc7x31xedx8b" "x34xafx01xc6x45x81x3ex46x61x74x61x75xf2x81x7e" "x08x45x78x69x74x75xe9x8bx7ax24x01xc7x66x8bx2c" "x6fx8bx7ax1cx01xc7x8bx7cxafxfcx01xc7x68x79x74" "x65x01x68x6bx65x6ex42x68x20x42x72x6fx89xe1xfe" "x49x0bx31xc0x51x50xffxd7"; int HextoBin(char* input) { FILE* fp; if ((fp = fopen(input,"wb")) == NULL) { printf("[-]:HextoBin files:%s not find ",input); return 0; } fwrite(shellcode,1,sizeof(shellcode) -1,fp); fclose(fp); printf("[*]:Bin files suscess Convert,check Files:%s ",input); return 0; } int Bin2Hex(char* src,char* des) { FILE *fi,*fo; unsigned int n; int c; if ((fi = fopen(src,"rb")) == NULL) { cprintf("Can not find file %s",src); return 0; } if ((fo=fopen(des,"w"))==NULL) { fclose(fi); cprintf("Can not create file %s",des); return 0; } n=0; while (1) { c=fgetc(fi); if (EOF==c) break; n++; if (1==n) fprintf(fo, ""\x%02X",c); else { if (1==n%16) fprintf(fo,"" "\x%02X",c); else fprintf(fo, "\x%02X",c); } } fprintf(fo,"""); fcloseall(); cprintf("OK to Bin2Hex %u bytes.",n); return 0; } void help(char* proc) { printf("[-]:%s Srcfile Descfile ",proc); printf("[-]:%s -hex shellcode.bin Convert.hex ",proc); printf("[-]:%s -bin Convert.bin ",proc); } //------------------------------------------------------- int main(int argc,char *argv[]) { if (argc == 4) { if (stricmp(argv[1],"-hex") == 0) { char* src = argv[2]; char* des = argv[3]; Bin2Hex(src,des); }else { help(argv[0]); exit(0); } }else if (argc == 3) { if (stricmp(argv[1],"-bin") == 0) { char* outfile = argv[2]; HextoBin(outfile); }else { help(argv[0]); exit(0); } }else { help(argv[0]); exit(0); } return 0; }
详细参数说明:
当把shellcode写入代码shellcode变量的时候,输入-bin shellcode.bin 将生成二进制文件数据流。
当需要把二进制数据流转换成hex(16进制的时候)输入-hex shellcode.bin hex.hex
具体请看代码。这是博主自己的学习笔记,请勿喷。