ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Linux shellcode sample

2019-04-30 17:38:08  阅读:227  来源: 互联网

标签:x31 xor shellcode mov xff sample Linux ebx


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 '\t' ' ' | sed 's/ $//g' | sed 's/ /\\x/g' | paste -d '' -s | sed 's/^/"/' | sed 's/$/"/g'

 

"\xeb\x19\x31\xc0\x31\xdb\x31\xd2\x31\xc9\xb0\x04\xb3\x01\x59\xb2\x05\xcd\x80\x31\xc0\xb0\x01\x31\xdb\xcd\x80\xe8\xe2\xff\xff\xff\x6d\x69\x6c\x75"

 

#include <stdio.h>
#include <string.h>

unsigned char code[] ="\xeb\x19\x31\xc0\x31\xdb\x31\xd2\x31\xc9\xb0\x04\xb3\x01\x59\xb2\x05\xcd\x80\x31\xc0\xb0\x01\x31\xdb\xcd\x80\xe8\xe2\xff\xff\xff\x6d\x69\x6c\x75";

main(){
    printf("Shellcode Length: %d\n", 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

 

标签:x31,xor,shellcode,mov,xff,sample,Linux,ebx
来源: https://www.cnblogs.com/lsgxeva/p/10797300.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有