汇编引擎 - Keystone实用手册

工具 · 2021-07-21
汇编引擎 - Keystone实用手册

本文就是写写Keystone咋用的(Python)
不涉及原理层面

地址

官方网站
https://www.keystone-engine.org/
Github
https://github.com/keystone-engine/keystone

介绍

Keystone是一个轻量级的多平台多架构的汇编框架,可以提供不少独特功能:

  • 支持多框架:Arm, Arm64 (AArch64/Armv8), Ethereum Virtual Machine, Hexagon, Mips, PowerPC, Sparc, SystemZ & X86 (包括 16/32/64bit)。
  • 干净/简单/轻量级/直观的API,同时不依赖任何架构。
  • 以C/C++实现,可在众多语言里使用:Java、Masm、C#、PowerShell、Perl、Python、NodeJS、Ruby、Go、Rust、Haskell、VB6 和 OCaml。
  • 原生支持Windows和*nix系统(以下系统已确认支持:Mac OSX, Linux, *BSD, Solaris)
  • 线程安全的设计。
  • 开源,具有双重许可证

使用

编译ShellCode(X86)

Input

from keystone import *
import sys

Shellcode_instruction = '''
xor    eax, eax
push    eax
push    0x68732f2f
push    0x6e69622f
mov    ebx, esp
push    eax
push    ebx
mov    ecx, esp
mov    al, 0xb
int    0x80
'''

KS = Ks(KS_ARCH_X86, KS_MODE_64)
code, count = KS.asm(Shellcode_instruction)
print(f"Source\t{code}")
print(f"Bytes\t{b''.join(map(lambda x: x.to_bytes(1, sys.byteorder), code))}")
print(f"Count\t{count}")

Output

Source    [49, 192, 80, 104, 47, 47, 115, 104, 104, 47, 98, 105, 110, 137, 227, 80, 83, 137, 225, 176, 11, 205, 128]
Bytes    b'1\xc0Ph//shh/bin\x89\xe3PS\x89\xe1\xb0\x0b\xcd\x80'
Count    11

编译ShellCode(X86-64)

Input

from keystone import *
import sys

Shellcode_instruction = '''
xor    rdx, rdx
mov    rbx, 0x68732f6e69622f2f
shr    rbx, 0x8
push    rbx
mov    rdi, rsp
push    rax
push    rdi
mov    rsi, rsp
mov    al, 0x3b
syscall
'''

KS = Ks(KS_ARCH_X86, KS_MODE_64)
code, count = KS.asm(Shellcode_instruction)
print(f"Source\t{code}")
print(f"Bytes\t{b''.join(map(lambda x: x.to_bytes(1, sys.byteorder), code))}")
print(f"Count\t{count}")

Output

Source    [72, 49, 210, 72, 187, 47, 47, 98, 105, 110, 47, 115, 104, 72, 193, 235, 8, 83, 72, 137, 231, 80, 87, 72, 137, 230, 176, 59, 15, 5]
Bytes    b'H1\xd2H\xbb//bin/shH\xc1\xeb\x08SH\x89\xe7PWH\x89\xe6\xb0;\x0f\x05'
Count    10
keystone 汇编 引擎
  1. Ghiryg 25 天前

    ferrous sulfate 100 mg generic order betapace 40mg without prescription betapace 40mg without prescription

  2. Czqmmj 27 天前

    buy monograph 600 mg sale oral pletal 100 mg buy pletal medication

  3. Zmnazs 28 天前

    where can i buy prasugrel purchase chlorpromazine without prescription tolterodine 1mg pills

  4. Ckwdfe 31 天前

    order florinef 100mcg online buy generic rabeprazole imodium price

  5. Ppptcx 31 天前

    duphaston for sale online order duphaston 10mg generic order jardiance 25mg sale

  6. Rcrjtm 08-28

    meloset where to buy meloset buy online order danazol 100mg generic

  7. Chphsn 08-27

    order dipyridamole 100mg pill dipyridamole price pravachol 20mg canada

  8. Xbmjtw 08-26

    aspirin 75 mg brand imiquad usa how to get imiquad without a prescription

  9. Aktrre 08-22

    order mintop generic cialis pills low cost ed pills

  10. Sbsglu 08-22

    generic acarbose buy generic precose 25mg buy griseofulvin

  11. Ftcsbz 08-20

    cialis walmart sildenafil ca buy sildenafil tablets

  12. Apifyb 08-20

    zaditor 1 mg us ziprasidone where to buy buy imipramine medication

  13. Oyifal 08-11

    tricor 200mg ca order fenofibrate 160mg without prescription order tricor 200mg generic

Theme Jasmine by Kent Liao