zoukankan      html  css  js  c++  java
  • Linux shellcode sample

    Linux shellcode sample

    ;HelloWorld.asm
    ;Author: Kul Subedi
    
    global _start
    
    section .text
        _start:
            ; print HelloWorld! in screen
            mov eax, 0x4
            mov ebx, 0x1
            mov ecx, message
            ;mov edx, 12
            mov edx, mlen
            int 0x80
    
            ; exit program gracefully
            mov eax, 0x1
            mov ebx, 0x5
            int 0x80
    
    section .data
        message: db "Welcome to Assembly!"
        mlen equ $-message
    
     
    ;hello.asm
    [SECTION .text]
    
    global _start
    
    
    _start:
    
            jmp short call_shellcode
    
            shellcode:
    
            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
    
            call_shellcode:
            call shellcode	;put the address of the string on the stack
            db 'milu'
    #!/usr/bin/env bash
    
    echo '[+] Assembling with Nasm .. '
    nasm -f elf32 -o $1.o $1.nasm
    echo '[+] Linking ... '
    ld -o $1 $1.o
    echo '[+] Done!'
    
     
    #!/usr/bin/env bash
    
    objdump -d $1 | grep '[0-9a-f]:' | grep -v 'file' | cut -d: -f2|cut -d' ' -f1-6 | tr -s ' ' | tr '	' ' ' | sed 's/ $//g' | sed 's/ /\x/g' | paste -d '' -s | sed 's/^/"/' | sed 's/$/"/g'
    "xebx19x31xc0x31xdbx31xd2x31xc9xb0x04xb3x01x59xb2x05xcdx80x31xc0xb0x01x31xdbxcdx80xe8xe2xffxffxffx6dx69x6cx75"
    #include <stdio.h>
    #include <string.h>
    
    unsigned char code[] ="xebx19x31xc0x31xdbx31xd2x31xc9xb0x04xb3x01x59xb2x05xcdx80x31xc0xb0x01x31xdbxcdx80xe8xe2xffxffxffx6dx69x6cx75";
    
    main(){
        printf("Shellcode Length: %d
    ", strlen(code));
    
        int (*ret)() = (int(*)())code;
    
        ret();
    }
    #!/usr/bin/env bash
    
    echo '[+] Compiling....'
    
    gcc -fno-stack-protector -z execstack $1.c -o $1
    
    echo '[+] Done...'

    ============== End

  • 相关阅读:
    MOSS 之 自定义MembershipProvider实现Forms方式验证——学习实战篇
    (转)jquery.validate全攻略
    LinQ To Entity的增删改查(转)
    如何将程序集(.dll文件)添加到GAC(全局程序集缓存)?
    CSS Sprites (转)
    如何查看MOSS未知错误?
    用.Net开发Windows服务初探(转)
    早该知道的7个JavaScript技巧(转)
    最容易犯的13个JavaScript错误——转
    jQuery插件开发全解析(转)
  • 原文地址:https://www.cnblogs.com/lsgxeva/p/10797300.html
Copyright © 2011-2022 走看看