需要建议:使用 shellcode 对 pdf 进行逆向工程

逆向工程 恶意软件 漏洞分析 调用栈 外壳代码
2021-06-18 20:57:17

问题

我试图找到隐藏在用 shellcode 内置的 pdf 中的明文

我试过的

我收到了一个包含 javascript 的 pdf,我按如下方式挖掘 pdf:

探索 JavaScript 内部

root@kali:~# pdfid APT9001.pdf 
PDFiD 0.0.12 APT9001.pdf
 PDF Header: %PDF-1.5
 obj                   10
 endobj                 9
 stream                 3
 endstream              3
 xref                   2
 trailer                2
 startxref              2
 /Page                  3(2)
 /Encrypt               0
 /ObjStm                0
 /JS                    1(1)
 /JavaScript            1(1)
 /AA                    0
 /OpenAction            1(1)
 /AcroForm              0
 /JBIG2Decode           1(1)
 /RichMedia             0
 /Launch                0
 /EmbeddedFile          0
 /Colors > 2^24         0

提取时:

root@kali:~# pdf-parser -s javascript APT9001.pdf 
obj 5 0
 Type: /Action
 Referencing: 6 0 R

  <<
    /Type /Action
    /S /JavaScript
    /JS 6 0 R
  >>


root@kali:~# pdf-parser -o 6 APT9001.pdf 
obj 6 0
 Type: 
 Referencing: 
 Contains stream

  <<
    /Length 6170
    /Filter '[  \r\n /Fla#74eDe#63o#64#65  /AS#43IIHexD#65cod#65 ]'
  >>


root@kali:~# pdf-parser -o 6 -d APT9001.js -f APT9001.pdf 
obj 6 0
 Type: 
 Referencing: 
 Contains stream

  <<
    /Length 6170
    /Filter '[  \r\n /Fla#74eDe#63o#64#65  /AS#43IIHexD#65cod#65 ]'
  >>

如果我打开 JavaScript 文件,我可以快速找到 shellcode:

%u72f9%u4649%u1525%u7f0d%u3d3c%ue084%ud62a%ue139%ua84a%u76b9%u9824%u7378%u7d71%u757f%u2076%u96d48%fub3%u96d419%ubu7%ubu7%ubu7%ubu3%ubu3%ubu7%cub3%ubu3%ub37%cub7904 %u7e24%u437c%ue180%ub115%ub3b2%u4f66%u27b6%u9f3c%u7a4e%u412d%ubbbf%u7705%uf528%u9293%u9990%ua998%u4ebb%ud4%ud4%ud4%ud4%ud4%ud4%u7a4e%u7e24%u437%ud4 %ue031%u3572%ud610%u6740%u2bbe%u4afd%u041c%u3f97%ufc3a%u7479%u421d%ub7b5%u0c2c%u130d%u25f8%u76b0%u7bbu1%u76b0%u7bbu1%udu20%cudu20%udu7u20%cub20%udbudu70u20%udbu70u7u20u7u20%udu20%udu7u20u7u20%udu20%u3f97%ufc3a%u7479%u421d%ub7b5%u0c2c2c %u3b96%u49d4%ud56b%u03b7%ue1f7%u467d%u77b9%u3d42%u111d%u67e0%u4b92%ueb85%u2471%u9b48%uf902%u4f15%u04ba%ue300%u8727%u9fd6%u4770%u187a%u73e2%ufd1b%u2574 %u437c%u4190%u97b6%u1499%u783c%u8337%ub3f8%u7235%u693f%u98f5%u7fbe%u4a75%ub493%ub5a8%u21bf%ufc0%u327bu2%u7u4%u7u28u7u27u28u7u27u28u7u28u7u28u7u27u28u7u7u7u4 %u492d%u8d42%u75b3%uf523%u727f%ufc0b%u0197%ud3f7%u90f9%u41be%ua81c%u7d25%ub135%u7978%uf80a%ufd32%u9219%bubbb4%u77b8%u707e%u4073%u0c7a%ud689%u2491%u1446%u9fba%uc087%u0dd4%u4bb0%ub62f%ue381%u0574%u3fb9%u1b67%u86b3%u4%u4%u4%u4%u4%u837u37%u84%u4%u837u36e u3d27%u4f75%u8cbf%u43e2%ub899%u3873%u7deb%u257a%uf985%ubb8d%u7f91%u9667%ub292%u4879%u4a3c%ud433%u97%u903%u97%u903%u97a%u903%u97%u903%u97a%u903%u34%u903%u34%u903%u34%u903%u34%u904%u985%u34%u985%u34%u95%u34%u904 ua8d6%u8814%uf8d1%u4272%u76ba%ufd08%ube41%ub54b%u150d%u4377%u1174%u78e3%ue020%u041c%u40bf%ud510%u40bf%ud510%ub727%ubu%ubf%ub4%ubu%ub4%ub4%ub4%ub4%ub4%ub4%ub4%ub4%ub4%ub4%ub4%ub4%ub4%ub4%u150d%u4377% u342d%u0c66%ub099%u7b49%u787a%u7f7e%u7d73%ub946%ub091%u928d%u90bf%u21b7%ue0f6%u134b%u29f5%u67ebue%u256%u96%u96%u96%u96%u96%u96%u96%u96%u96%u96%u96%u96%u96%u986%u96%u96%u96%u98% ub4ba%ub52c%uf812%u4f93%u7b76%u3079%ubefd%u3f71%u4e40%u7cb3%u2775%ue209%u4324%u0c70%u182d%u02e3%u4af9%u4%ub4%u4%u4%ub3%u4af9%u4%ub4%ub4%u46%ub4%u46%u40%u400%u400%u40%u40%u400%u400%u7000%u46%u40%u400%u7cb3%u2775%ue209%u4324%u182d ufc84%u497d%u7eb8%ud26b%u1de0%u0d76%u3174%u14eb%u3770%u71a9%u723d%ub246%u2f78%u047f%ub6a9%u1c7b%u3a173%u93be%u34f9%ud500%u037a%ue2f8%ub024%ufd4e%u3d79%u7596%u9b15%u7c49%ub42f%u9f4f%u4799%uc13b%ue3d0%u4014%u903%udub4%udub4%u903%udub28%udub28%udub84%udub37%udu84 u9267%ub198%ufc1a%ud4b9%ub32c%ubaf5%u690c%u91d6%u04​​a8%u1dbb%u4666%u2505%u35b7%u3742%u4b27%ufc90%ud23258%ub3%ub3%ub3%ub3%ub3%ub3%ub3%ub3%ub3%ub3%ub3%ub3%ub3%u825%u85%ub3%u91d6%u04​​a8%u1dbb%u4666%u2505%u35b7%u9267%ub198%ufc1a%ud4b9%ub32c%ubaf5%u690c%u91d6%u04​​a8%u1dbb%u4666%u2505%u35b7%u4b27% ub1c9%u3318%u33ff%uacc0%u613c%u027c%u202c%ucfc1%u030d%ue2f8%u81f0%u5bff%u4abc%u8b6a%u105a%u128b%uda75%u53%ub3%u75%u53%ub3%u75%u53%ub3%u75%u53%ub303%u75%u53%ub303% uf303%uc933%uad41%uc303%u3881%u6547%u5074%uf475%u7881%u7204%u636f%u7541%u81eb%u0878%u6464%u6572%u495%u65%u78%u78u37u78u78u78u37u78u37u78u78u78u36%u75%u78u38u78u204 u8e14%ud303%u3352%u57ff%u6168%u7972%u6841%u694c%u7262%u4c68%u616f%u5464%uff53%u68d2%u3233%u0101%u268%u4%u70%u4%u4%u4%u70%u4%u4%u706%u78%u4%u706%u75%u7061%u706%u7260%u76%u726%u7262%u68%u7262%u68%u780%u706%u76%u726%u76%u726%u726%u68%u726%u610%u726%u610%u70%u76%u76%u76%u76%u7262%u68%u616f%u5464% udf8b%u5c88%u0324%u6168%u6567%u6842%u654d%u7373%u5054%u54ff%u2c24%u6857%u2144%u2121%u4f68%u4e570%u8000%u0000%u148b%u8124%u0b72%ua316%u32fb%u7968%ubece%u8132%u1772%u45ae%u48cf%uc168%ue12b%u812b%u2372%u361%u82%u84%u84%u84%u84%u84%u87u70u4%u787u7207%u72%u77%u78%u782%u72%u82%u772%u72%u72%u72%u72%u82%u72%u82%u72%u8132%u45ae%u48cf%u8124%u148b%u8124%u0b72%u7968%ubece%u8132% %ucfe9%u8160%u3b72%u93be%u43a9%ud268%u98a3%u8137%u4772%u8a82%u3b62%uef68%u11a4%u814b%u5372%u47d66%ucc0%u47d6%ucc0%u47d6%ucc0%u47d6%ucc0%u47d6%ucc0%u47d6%ucc05%u47d6%ucc05%u47d6%u4772 %u8b52%u57cc%u5153%u8b57%u89f1%u83f7%u1ec7%ufe39%u0b7d%u3681%u4542%u4645%uc683%ueb04%ufff1%u68d0%u7365%u0173%udf8b%u5c88%u0324%u5068%u6f72%u6863%u7845 %u7469%uff54%u2474%uff40%u2454%u5740%ud0ff4645%uc683%ueb04%ufff1%u68d0%u7365%u0173%udf8b%u5c88%u0324%u5068%u6f72%u6863%u7845%u7469%uff54%u2474%uff4%u0324%u2474%u0324%u2474%u032544645%uc683%ueb04%ufff1%u68d0%u7365%u0173%udf8b%u5c88%u0324%u5068%u6f72%u6863%u7845%u7469%uff54%u2474%uff4%u0324%u2474%u0324%u2474%u03254

现在我被这部分困住了,现在我该如何进一步探索:

我可能认为的可能解决方案

将这些 shellcode 转换为 exe 并在文本恢复后将其导出为 txt 探索它的堆栈{假设]

我走对了路吗?或者任何社区的想法来进一步对这些进行逆向工程?

2个回答

shellcode 是unicode 转义的您可以使用简单的 Python 脚本将其转换为十六进制表示。

from binascii import unhexlify as unhx

encoded = open('encoded.txt').read() # The shellcode dump
out = open('shellcode.bin', 'wb')

for s in encoded.split('%'):
    if len(s) == 5:
        HI_BYTE = s[3:]
        LO_BYTE = s[1:3]
        out.write(unhx(HI_BYTE))
        out.write(unhx(LO_BYTE))
out.close()

shellcode.bin包含二进制形式的 shellcode。您可以使用下面的C ++模板或使用在线工具的shellcode转换为可执行文件,如

#include <stdio.h>

unsigned char payload[] = 
{
//Bytes of the shellcode
};

int main(int argc, char **argv) {
    (*(void (*)()) payload)();
    return(0);
}

运行生成的可执行文件会产生此输出。

在此处输入图片说明

极端程序员的回答很棒,我也想在这里分享我的方法:

我使用 REMnux 中的工具将其转换为可执行文件:

remnux@remnux:~$ unicode2hex-escaped < sc.txt > sc2.txt
remnux@remnux:~$ shellcode2exe -s sc2.txt 


Reading string shellcode from file sc2.txt
Generating executable file
Writing file sc2.exe
Done.
remnux@remnux:~$ 

shellcode 把一些东西放到栈上:

在此处输入图片说明

如果我拆分它并仔细观察:

在此处输入图片说明

所以我猜的答案是 wa1ch.d3m.spl01ts@flare-on.com