zoukankan      html  css  js  c++  java
  • How to make shellcode

    ;hello.asm
    [SECTION .text]
    
    global _start
    
    
    _start:
    
            jmp short ender
    
            starter:
    
            xor eax, eax    ;clean up the registers
            xor ebx, ebx
            xor edx, edx
            xor ecx, ecx
    
            mov al, 4       ;syscall write
            mov bl, 1       ;stdout is 1
            pop ecx         ;get the address of the string from the stack
            mov dl, 5       ;length of the string
            int 0x80
    
            xor eax, eax
            mov al, 1       ;exit the shellcode
            xor ebx,ebx
            int 0x80
    
            ender:
            call starter	;put the address of the string on the stack
            db 'hello'
    
    

    $ nasm -f elf hello.asm
    $ ld -o hello hello.o
    $ objdump -d ./PROGRAM|grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut -f1-6 -d' '|tr -s ' '|tr '\t' ' '|sed 's/ $//g'|sed 's/ /\\x/g'|paste -d '' -s |sed 's/^/"/'|sed 's/$/"/g'

    or
    by python
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    from subprocess import Popen, PIPE
    import sys
     
    def shellcode_from_objdump(obj):
        res = ''
        p = Popen(['objdump', '-d', obj], stdout=PIPE, stderr=PIPE)
        (stdoutdata, stderrdata) = p.communicate()
        if p.returncode == 0:
            for line in stdoutdata.splitlines():
                cols = line.split('\t')
                if len(cols) > 2:
                    for b in [b for b in cols[1].split(' ') if b != '']:
                        res = res + ('\\x%s' % b)
        else:
            raise ValueError(stderrdata)
     
        return res
     
     
    if __name__ == '__main__':
        if len(sys.argv) < 2:
            print 'Usage: %s <obj_file>' % sys.argv[0]
            sys.exit(2)
        else:
            print 'Shellcode for %s:' % sys.argv[1]
            print shellcode_from_objdump(sys.argv[1])
        sys.exit(0)
    
    
     
  • 相关阅读:
    Floppy Disk Driver Primer
    王少川: 现阶段 我国没必要开发自己的操作系统
    Why does DOS use 100% CPU under Virtual PC?
    “情感计算”的危机与哲学错误
    [转载] 国产OS? 中文CPU?
    理想与现实的关系思考
    在Virtual PC 中安 装ms dos 6.22 的方法
    How Microsoft Lost the API War.
    svn 功能概览
    as3里的regex不需要转义
  • 原文地址:https://www.cnblogs.com/bittorrent/p/2741721.html
Copyright © 2011-2022 走看看