USB Forensics
一个基于USB流量的PCAP文件,可能是USB-鼠标、键盘、存储设备的流量。拿到数据后首先来看看USB连接了什么设备。使用wireshark检查数据包:
1 0.000000 host 1.12.0 USB 36 GET DESCRIPTOR Request DEVICE
2 0.000306 1.12.0 host USB 46 GET DESCRIPTOR Response DEVICE
在GET DESCRIPTOR返回包中,有idVendor和idProduct字段,根据此数据我们可以知道它是键盘、鼠标还是存储设备。
DEVICE DESCRIPTOR
bLength: 18
bDescriptorType: 0x01 (DEVICE)
bcdUSB: 0x0200
bDeviceClass: Device (0x00)
bDeviceSubClass: 0
bDeviceProtocol: 0 (Use class code info from Interface Descriptors)
bMaxPacketSize0: 8
idVendor: Razer USA, Ltd (0x1532)
idProduct: BlackWidow Ultimate 2013 (0x011a)
bcdDevice: 0x0200
iManufacturer: 1
iProduct: 2
iSerialNumber: 0
bNumConfigurations: 1
USB-Keyboard
如果设备连接的是键盘,我们可以检查interrupt in消息。
51 8.808610 1.12.1 host USB 35 URB_INTERRUPT in
检查 the Leftover Capture Data field:
Frame 159: 35 bytes on wire (280 bits), 35 bytes captured (280 bits)
USB URB
[Source: 1.12.1]
[Destination: host]
USBPcap pseudoheader length: 27
IRP ID: 0xffffa5045d1653c0
IRP USBD_STATUS: USBD_STATUS_SUCCESS (0x00000000)
URB Function: URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER (0x0009)
IRP information: 0x01, Direction: PDO -> FDO
URB bus id: 1
Device address: 12
Endpoint: 0x81, Direction: IN
URB transfer type: URB_INTERRUPT (0x01)
Packet Data Length: 8
[bInterfaceClass: HID (0x03)]
Leftover Capture Data: 0000500000000000
我们使用tshark来取出数据,保存为usb.capdata。
tshark -r usb-keyboard-data.pcap -T fields -e usb.capdata
00:00:08:00:00:00:00:00
00:00:00:00:00:00:00:00
00:00:0e:00:00:00:00:00
00:00:00:00:00:00:00:00
00:00:16:00:00:00:00:00
每一数据有8个字节。
Keyboard Report Format
- Byte 0: Keyboard modifier bits (SHIFT, ALT, CTRL etc)
- Byte 1: reserved
- Byte 2-7: Up to six keyboard usage indexes representing the keys that are currently “pressed”. Order is not important, a key is either pressed (present in the buffer) or not pressed.
键盘发送 02 00 0e 00 00 00 00 00,表示同时按下了Left Shift + k,即大写K。
具体键位对应参见Hut1_12v2.pdf第53页。
USB HID Keyboard Scan Codes
MightyPork根据USB规范1.11编写了一个USB HID键盘扫描码,记录在usb_hid_keys.h。
可参考以上代码内容编写脚本,转换usb.capdata的数据来查看用户的键盘使用记录!
whoami已经写了一个Python脚本:
usb_codes = {
0x04:“aA”, 0x05:“bB”, 0x06:“cC”, 0x07:“dD”, 0x08:“eE”, 0x09:“fF”,
0x0A:“gG”, 0x0B:“hH”, 0x0C:“iI”, 0x0D:“jJ”, 0x0E:“kK”, 0x0F:“lL”,
0x10:“mM”, 0x11:“nN”, 0x12:“oO”, 0x13:“pP”, 0x14:“qQ”, 0x15:“rR”,
0x16:“sS”, 0x17:“tT”, 0x18:“uU”, 0x19:“vV”, 0x1A:“wW”, 0x1B:“xX”,
0x1C:“yY”, 0x1D:“zZ”, 0x1E:“1!”, 0x1F:“2@”, 0x20:“3#”, 0x21:“4$”,
0x22:“5%”, 0x23:“6^”, 0x24:“7&”, 0x25:“8*”, 0x26:“9(”, 0x27:“0)”,
0x2C:" “, 0x2D:”-_", 0x2E:"=+", 0x2F:"[{", 0x30:"]}", 0x32:"#~",
0x33:";:", 0x34:"’"", 0x36:",<", 0x37:".>", 0x4f:">", 0x50:"<"
}
lines = ["","","","",""]
pos = 0
for x in open(“data1.txt”,“r”).readlines():
code = int(x[6:8],16)
if code == 0:
continue
newline or down arrow - move down
if code == 0x51 or code == 0x28:
pos += 1
continue
up arrow - move up
if code == 0x52:
pos -= 1
continue
select the character based on the Shift key
if int(x[0:2],16) == 2:
lines[pos] += usb_codes[code][4]
else:
lines[pos] += usb_codes[code][0]
for x in lines:
print x
USB-Mouse
如果我们捕获USB鼠标的流量数据,可以发现记录数据使用了四个字节。鼠标移动时表现为连续性,与键盘击键的离散性不一样,不过实际上鼠标动作所产生的数据包也是离散的。
第一个字节有一堆flag标志,它代表鼠标按键。0代表未按键,1代表左键,2代表右键,其余字段看意思。
byte 1:
Y overflow X overflow Y sign bit X sign bit Always 1 Middle Btn Right Btn Left Btn
第二个字节是“X”的值,它代表鼠标在水平方向的移动,向左为负。
byte 2:
X movement
第三个字节是“Y”的值,它代表鼠标在垂直方向的移动,向下(朝向用户)为负。
byte 3:
Y movement
第四个字节是扩展字节,当鼠标有滚轮的时候才会被激活。
假设我们已经将这些数据捕获到一个文件中,我们可以从中直接提取鼠标移动的数据,
tshark -r challenge.pcapng usb.capdata and usb.device_address12 -T fields -e usb.capdata > mouse_data.txt
这里可以使用GNUplot来绘制,参考 Riverside
awk -F: 'function comp(v){if(v>127)v-=256;return v}{x+=comp(strtonum(“0x”$2));y+=comp(strtonum(“0x”$3))}$1"01"{print x,y}’ mouse_data.txt > click_coordinates.txt
GNUplot
gnuplot -e “plot ‘click_coordinates.txt’“
如果鼠标移动在屏幕键盘上,我们可以使用
awk 'BEGIN{split(” zxcvbnm asdfghjkl qwertyuiop”,key,//)}{r=int(($2-20)/-100);c=int((
1
−
117
+
(
r
1 - 117 + (r % 2 * 40)) / 85);k=r*10+c;printf "%s",key[k]}END{print""}' click_coordinates.txt
USB-Storage-Device
如果在PCAP文件中发现设备是一个USB-Storage-Device设备,就需要关注URB_BULK out/in字段大小大于1000字节的数据流,然后提取出来(选择或标记数据流,File,Export Packet Bytes)。
Esoteric Languages
参考 Esoteric programming language
- Piet : Piet is a language designed by David Morgan-Mar, whose programs are bitmaps that look like abstract art. (Steganography - Challenges)
- Malbolge : Malbolge is a public domain esoteric programming language invented by Ben Olmstead in 1998, named after the eighth circle of hell in Dante’s Inferno, the Malebolge
内存取证(Memory Forensics)
Volatility
Command Reference
注意一些关键的命令:
- imageinfo/ pslist / cmdscan/ consoles/ consoles/ memdump/ procdump/ filescan/ connscan/
- Extract files using filescan and dumpfiles
从内存中提取RAW图片
Extracting RAW pictures from Memory Dumps
- 重命名
*.dmp
文件后缀为*.data
,下载并安装GIMP,然后使用“RAW Image Data”格式打开。 - 我们可以使用GIMP将内存dump并分析相应偏移量上的渲染pixels/bitmaps。
磁盘取证(Disk Forensics)
RAID
RAID ( Redundant Array of Independent Disks )即独立磁盘冗余阵列,通常简称为磁盘阵列。
简单地说, RAID 是由多个独立的高性能磁盘驱动器组成的磁盘子系统,从而提供比单个磁盘更高的存储性能和数据冗余的技术。
在用户看起来,组成的磁盘组就像是一个硬盘,用户可以对它进行分区,格式化等等。总之,对磁盘阵列的操作与单个硬盘一模一样。不同的是,磁盘阵列的存储速度要比单个硬盘高很多,而且可以提供自动数据备份。数据备份的功能是在用户数据一旦发生损坏后,利用备份信息可以使损坏数据得以恢复,从而保障了用户数据的安全性。
关于Raid0,Raid1,Raid5,Raid10的总结。
Challenges
如果我们提供两到三个RAID磁盘文件,其中一个损坏了,但我们是可以恢复它的。
1−117+(rfile disk*
disk0: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID “mkfs.fat”, sectors/cluster 4, root entries 512, sectors 2048 (volumes <=32 MB) , Media descriptor 0xf8, sectors/FAT 2, sectors/track 32, heads 64, reserved 0x1, serial number 0x867314a9, unlabeled, FAT (12 bit)
disk1: ASCII text
disk2: data
$ ls -lh
512K disk0
12 disk1
512K disk2
$ cat disk1
crashed )
从结果可以看出disk1损坏了。但也看出了这里使用了RAID。 RAID允许如果3个磁盘丢失1个,通过异或其他两个磁盘可以获得每个磁盘的版本。 我们使用python来异或disk0和disk2来获取disk1:
from pwn import *
with open(“disk0”, “rb”) as f1:
with open(“disk2”, “rb”) as f2:
with open(“disk1”, “wb”) as f3:
x = f1.read()
y = f2.read()
f3.write(xor(x,y))
或者可以使用xor-files对两个或多个文件进行异或。
现在,为了得到完整的NAS内容,我们必须确定数据块的分布。在分析了磁盘内容,了解了一些FAT12结构后,我们已经确定奇偶校验块(BP)位于每行的不同磁盘上,因此我们有:
D0 | D1 | D2
—|----|—
B0 | B1 | BP
B2 | BP | B3
BP | B4 | B5
B6 | B7 | BP
使用python将所有的数据块拼凑起来:
n = 1024
k = 512 # block size
with open(“disk0”, “rb”) as f1:
with open(“disk1”, “rb”) as f2:
with open(“disk2”, “rb”) as f3:
with open(“disk_out”, “wb”) as f_out:
x = 2
for _ in xrange(n):
blocks = (f1.read(k), f2.read(k), f3.read(k))
data_blocks = [b for i, b in enumerate(blocks) if i != x]
x = (x - 1) % 3
f_out.write("".join(data_blocks))
现在我们可以挂载新生成磁盘来检查内容。
格式(Formats)
Boarding Pass Format
机场签发的登机牌 from What’s contained in a boarding pass barcode?
M1EWING/SHAUN E1AAAAA SYDBNEQF 0524 106Y023A0073 359>2180
B 29 0 QF 1245678 128
登机牌条形码上有很多信息,解释如下:
- M1 : Format code ‘M’ and 1 leg on the boarding pass.
- EWING/SHAUN : My name.
- E1AAAAA : Electronic ticket indicator and my booking reference.
- SYDBNEQF : Flying from SYD (Sydney) to BNE (Brisbane) on QF (Qantas).
- 0524 : Flight number 524.
- 106 : The Julian date. In this case 106 is April 16.
- Y : Cabin – Economy in this case. Others including F (First) and J (Business).
- 23A : My seat.
- 0073 : My sequence number. In this case I was the 73rd person to check-in.
- 3 : My “passenger status”.
- 59 : There is a various size field. This is the size
- > : Beginning of the version number
- 2 : The version number.
- 18 : Field size of another variable field.
- 0 : My check-in source.
- B : Airline designator of boarding pass issuer.
- 2 : Another variable size field.
- 9 : Airline code.
- 0 : International document verification. ’0′ as I presume is not applicable.
- QF : The airline my frequent flyer account is with.
- 1245678 : My frequent flyer number.
- 128 : Airline specific data.
Interesting Blog
- APT-Incident-Response
- Securityfest CTF - Coresec challenge writeup
- SHX7 - for300
Others
- Unicode
安卓逆向,下面提供三种反编译方法:
IOS包,使用dpkg-deb来提取:
dpkg-deb -x com.yourcompany.whyos_4.2.0-28debug_iphoneos-arm.deb app
- disk…img文件,使用foremost提取,或修复文件头,文件尾,数据结构。
jar文件:
jar xf jar-file
x : extract files from the JAR archive.
f : JAR file from which files are to be extracted is specified on the command line, rather than through stdin.
The jar-file argument is the filename (or path and filename) of the JAR file from which to extract files.
- 如果是恶意代码文件,那么在真实的环境下执行做下比较来定位恶意代码。
- 摩尔斯代码,利用Transator。
有时候提取一些文件,会看到一些空名字文件:
ls -lb might be of help.
-b, --escape : print C-style escapes for nongraphic characters
打开一个文件名为-
的文件:
cat ./-
- Excel文档,可以尝试解压它,并检查其中的VBA宏。
GIF to JPG
convert animation.gif target.png
- 这一块像是作者随手的笔记…?!
转自:https://www.bodkin.ren/index.php/archives/702/
作者:SewellDinG 老锥