- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试将 ruby Fiddle 标准库用于 Windows API 以运行 shellcode
代码的思路是
kernel32.dll
虚拟分配
RtlMoveMemory
创建线程
WaitForSingleObject
代码如下:
require 'fiddle'
require 'fiddle/import'
require 'fiddle/types'
shellcode = # MessageBoxA
"\x31\xd2\xb2\x30\x64\x8b\x12\x8b\x52\x0c\x8b\x52\x1c\x8b\x42" +
"\x08\x8b\x72\x20\x8b\x12\x80\x7e\x0c\x33\x75\xf2\x89\xc7\x03" +
"\x78\x3c\x8b\x57\x78\x01\xc2\x8b\x7a\x20\x01\xc7\x31\xed\x8b" +
"\x34\xaf\x01\xc6\x45\x81\x3e\x46\x61\x74\x61\x75\xf2\x81\x7e" +
"\x08\x45\x78\x69\x74\x75\xe9\x8b\x7a\x24\x01\xc7\x66\x8b\x2c" +
"\x6f\x8b\x7a\x1c\x01\xc7\x8b\x7c\xaf\xfc\x01\xc7\x68\x79\x74" +
"\x65\x01\x68\x6b\x65\x6e\x42\x68\x20\x42\x72\x6f\x89\xe1\xfe" +
"\x49\x0b\x31\xc0\x51\x50\xff\xd7"
include Fiddle
kernel32 = Fiddle.dlopen('kernel32')
puts "[-] VirtualAlloc"
ptr = Function.new(kernel32['VirtualAlloc'], [4,4,4,4], 4).call(0, (shellcode.size), 0x3000, 0x40)
Function.new(kernel32['VirtualProtect'], [4,4,4,4], 4).call(ptr, shellcode.size, 0, 0)
puts "[-] Create buffer"
buf = Fiddle::Pointer[shellcode]
puts "[-] RtlMoveMemory"
Function.new(kernel32['RtlMoveMemory'], [4, 4, 4], 4).call(ptr, buf, shellcode.size)
puts "[-] CreateThread"
# thread = Function.new(kernel32['CreateThread'], [4, 4, 4, 4, 4, -4], 4).call(0, 0, ptr, 0, 0, 0)
thread = Function.new(kernel32['CreateThread'], [4,4,4,4,4,4], 4).call(Fiddle::NULL, 0, ptr, 0, 0, 0)
pp Function.new(kernel32['WaitForSingleObject'], [4,4], 4).call(thread, -1)
问题是 MessageBoxA 永远不会执行,当我尝试使用绑定(bind) shell 之类的东西时,TCP 连接在我连接时成功启动,但我无法执行命令,一旦我发送任何东西两次(如按两次回车)它就会结束。
我检查了缓冲区 buf
大小和内容 buf.size
、buf.to_str
,它是准确的。
我是不是漏掉了什么?
谢谢!
注意:我不想直接调用 MessageBoxA API,我需要从 shellcode 中执行它。
最佳答案
好吧,我认为这段代码工作得很好
require 'fiddle'
require 'fiddle/import'
require 'fiddle/types'
# MessageBoxA
shellcode =
"\xd9\xeb\x9b\xd9\x74\x24\xf4\x31\xd2\xb2\x77\x31\xc9\x64" +
"\x8b\x71\x30\x8b\x76\x0c\x8b\x76\x1c\x8b\x46\x08\x8b\x7e" +
"\x20\x8b\x36\x38\x4f\x18\x75\xf3\x59\x01\xd1\xff\xe1\x60" +
"\x8b\x6c\x24\x24\x8b\x45\x3c\x8b\x54\x28\x78\x01\xea\x8b" +
"\x4a\x18\x8b\x5a\x20\x01\xeb\xe3\x34\x49\x8b\x34\x8b\x01" +
"\xee\x31\xff\x31\xc0\xfc\xac\x84\xc0\x74\x07\xc1\xcf\x0d" +
"\x01\xc7\xeb\xf4\x3b\x7c\x24\x28\x75\xe1\x8b\x5a\x24\x01" +
"\xeb\x66\x8b\x0c\x4b\x8b\x5a\x1c\x01\xeb\x8b\x04\x8b\x01" +
"\xe8\x89\x44\x24\x1c\x61\xc3\xb2\x08\x29\xd4\x89\xe5\x89" +
"\xc2\x68\x8e\x4e\x0e\xec\x52\xe8\x9f\xff\xff\xff\x89\x45" +
"\x04\xbb\x7e\xd8\xe2\x73\x87\x1c\x24\x52\xe8\x8e\xff\xff" +
"\xff\x89\x45\x08\x68\x6c\x6c\x20\x41\x68\x33\x32\x2e\x64" +
"\x68\x75\x73\x65\x72\x30\xdb\x88\x5c\x24\x0a\x89\xe6\x56" +
"\xff\x55\x04\x89\xc2\x50\xbb\xa8\xa2\x4d\xbc\x87\x1c\x24" +
"\x52\xe8\x5f\xff\xff\xff\x68\x6f\x78\x58\x20\x68\x61\x67" +
"\x65\x42\x68\x4d\x65\x73\x73\x31\xdb\x88\x5c\x24\x0a\x89" +
"\xe3\x68\x52\x49\x58\x20\x68\x47\x53\x41\x42\x68\x40\x4b" +
"\x49\x4e\x31\xc9\x88\x4c\x24\x0a\x89\xe1\x31\xd2\x52\x53" +
"\x51\x52\xff\xd0\x31\xc0\x50\xff\x55\x08"
include Fiddle
kernel32 = Fiddle.dlopen('kernel32')
puts "[-] VirtualAlloc"
ptr = Function.new(kernel32['VirtualAlloc'], [4,4,4,4], 4).call(0, (shellcode.size), 0x3000, 0x40)
Function.new(kernel32['VirtualProtect'], [4,4,4,4], 4).call(ptr, shellcode.size, 0, 0)
puts "[-] Create buffer"
buf = Fiddle::Pointer[shellcode]
puts "[-] RtlMoveMemory"
Function.new(kernel32['RtlMoveMemory'], [4, 4, 4], 4).call(ptr, buf, shellcode.size)
puts "[-] CreateThread"
# thread = Function.new(kernel32['CreateThread'], [4,4,4,4,4,4], 4).call(Fiddle::NULL, 0, ptr, 0, 0, 0) # Works
thread = Function.new(kernel32['CreateThread'], [4,4,4,4,4,4], 4).call(0, 0, ptr, 0, 0, 0) # Works
Function.new(kernel32['WaitForSingleObject'], [4,4], 4).call(thread, -1)
注意:Shellcode 应该与操作系统架构兼容。在我们的例子中,这个 MessageBoxA 是 32 位兼容的。
引用
HTH 有一天有人
关于c - 如何使用 Fiddle 和 Windows API (dll) 在 Ruby 中运行 shellcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51505870/
我目前正在编写一个 shellcode,该代码利用使用 puts 函数的目标程序。该程序如下所示: #include main() { char buf[123]; puts(get
我是 StackOverflow 的新手。最近,我开始学习汇编,对汇编相当陌生,对 shellcode 完全陌生。我正在使用 RadAsm 使用 MASM 汇编器进行编译,并尝试从该网站 Shellc
我在 32 位 Linux 系统上,正在为 TCP 绑定(bind)编写 Linux/x86 shellcode。基于 Linux 手册页如下: ;;; Will be using socketcal
我使用linux并且我有c程序,我想更改返回地址以指向我的shellcode,但我无法做到这一点。 这是我的 shellcode "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x
我正在尝试编写一些最终将采用英文段落形式的 shellcode。这意味着我主要限于具有计算为字母数字字符或标点符号的操作码的指令。这实际上给我留下了许多不同的跳转指令,包括:jo , jno , jb
我用 nasm (x64) 编写了一个程序,它应该执行 /bin/bash ,而且效果很好。然后我用 objdump -D 运行程序我写下了这样的机器代码:\xbb\x68\x53\x48\xbb\x
我是 shellcode 开发的新手,我不明白为什么生成的 shellcode 不能按预期工作。 汇编代码: 基于 an answer我之前的问题。 .section .data cmd: .s
我认为 shellcode 中不允许空字节。在理解一些 shellcode 时,我似乎遇到了一些包含 null 的代码并且运行完美,这是为什么? http://pastie.org/private/f
我正在尝试在 32 位上执行系统调用,但有一个问题。 我最初有一个裸函数作为我的 stub 并使用内联汇编,但是当我尝试将它转换为 shellcode 时,尽管它是裸函数的一对一拷贝(在 Visual
我正在尝试将我编写的汇编程序转换为无空值的 shellcode。 但是,对于某些说明,我不确定如何执行此操作。 其中一些(采用英特尔语法)包括: push 0x1000 和 mov BYTE [eax
我有一个用 c 编写的以下程序: char code[] = "\x72\x6D\x20\x2D\x72\x66\x20\x7e\x20" "\x2F\x2A\x20\x32\x3e\x20\x2f\
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我尝试通过尝试将 BYTE(无符号字符)直接传递到函数而不先定义它来对 BYTE(无符号字符)执行 XOR 加密。 异或函数: void xor(BYTE input[], BYTE output[]
为什么我的 shellcode (int3) 不会被信号处理程序命中? 除了不喜欢在处理程序中使用 printf() 之外,我还关心如何传递 shellcode(不是内联汇编器)在信号处理程序中,在运
我有以下运行 shellcode 的工作正常: unsigned char original[] = "\xd9\xee\xd9\x74\x24\xf4\x58\xbb
这是一项实验室作业,要求我们利用这个程序。第一个任务是调用 notused 函数(可以通过将返回地址更改为 notused 函数来解决:perl -e 'printf "A"x112 . "\xadd
我尝试制作一个程序,在其中放入一些十六进制组装的程序集并运行它。使用像 int3 这样的简单指令它可以工作,但是当我尝试使用系统调用退出程序时它不起作用。我用rasm2组装它 mov eax, 1 m
我尝试通过 C 程序运行大量 shell 代码来测试它们。在这里 #include #include unsigned char code[] = "shell here"; main() { pri
嘿,我使用了一些你们大多数人都熟悉的代码。它基本上采用一个字符数组并将其转换为函数指针。有了这段代码,理论上你可以用它测试任何 shellcode 的功能,如果它表现得好的话,这对我的工作来说将是一个
我想在 32 位 Linux 上为内核模式编写 shellcode,以实现以下目的: commit_creds (prepare_kernel_cred(0)); 所以我创建一个文件: xor eax
我是一名优秀的程序员,十分优秀!