DLL注入之SHELLCODE數據轉換


 

 

#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <Windows.h>

char shellcode[] = "\x31\xd2\xb2\x30\x64\x8b\x12\x8b\x52\x0c\x8b\x52\x1c\x8b\x42"
    "\x08\x8b\x72\x20\x8b\x12\x80\x7e\x0c\x33\x75\xf2\x89\xc7\x03"
    "\x78\x3c\x8b\x57\x78\x01\xc2\x8b\x7a\x20\x01\xc7\x31\xed\x8b"
    "\x34\xaf\x01\xc6\x45\x81\x3e\x46\x61\x74\x61\x75\xf2\x81\x7e"
    "\x08\x45\x78\x69\x74\x75\xe9\x8b\x7a\x24\x01\xc7\x66\x8b\x2c"
    "\x6f\x8b\x7a\x1c\x01\xc7\x8b\x7c\xaf\xfc\x01\xc7\x68\x79\x74"
    "\x65\x01\x68\x6b\x65\x6e\x42\x68\x20\x42\x72\x6f\x89\xe1\xfe"
    "\x49\x0b\x31\xc0\x51\x50\xff\xd7";

int HextoBin(char* input)
{
    FILE* fp;
    if ((fp  = fopen(input,"wb")) == NULL)
    {
        printf("[-]:HextoBin files:%s not find\r\n",input);
        return 0;
    }

    fwrite(shellcode,1,sizeof(shellcode) -1,fp);
    fclose(fp);
    printf("[*]:Bin files suscess Convert,check Files:%s\r\n",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,"\"\n\"\\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\r\n",proc);
    printf("[-]:%s -hex shellcode.bin Convert.hex\r\n",proc);
    printf("[-]:%s -bin Convert.bin\r\n",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

 

具體請看代碼。這是博主自己的學習筆記,請勿噴。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM