2

cLEMENCy架构

 2 years ago
source link: https://taardisaa.github.io/2022/03/27/clemency/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

DEFCON比赛中使用的一个架构体系。很久以前就像研究,但是没怎么来得及。

cLEMENCy架构

Legitimate Business Syndicate: The cLEMENCy Architecture (legitbs.net)

the LEgitbs Middle ENdian Computer architecture

是一种很特殊的“中端序”架构体系。

  1. 内置调试器和反汇编器的cLEMENCy模拟器

clemency-201707271159.pdf (notmalware.ru)

现在同级文件夹下创建flag文件,因为不创建似乎程序没法正常启动。通过逆向得知,在自启动检查时有

if ( open("flag", 0) < 0 )
{
sub_402170("Error during IO init: unable to read flag file");
exit(-1);
}

的存在,没发现flag文件就会报错。


解决libreadline.so.6: cannot open shared object file: No such file or directory的问题_阿齐啦的博客-CSDN博客

有关libreadline.so.6找不到的问题。

cd /lib/x86_64-linux-gnu/
sudo ln -s libreadline.so.7.0 libreadline.so.6

./clemency-emu -d 1 hello.bin

执行1条指令后会停止,进入交互界面。

交互界面中输入u能够反汇编其余汇编指令。

q退出

bp    Add a breakpoint
bd Delete a breakpoint
bl List breakpoints
bpc Add a command to a breakpoint
dis Set commands to run when debug pauses execution
db Dump memory in bytes
dw Dump memory in words
dt Dump memory in tris
ds Dump memory as ascii string
e View or set exceptions to trigger on
er Exception Reset
g Go, continue execution
mp Display or set memory protections
p Run till next instruction
r Print or set registers
t Single step
u Unassemble
wb Write bytes
ww Write words
wt Write tris
q Exit
? Print info about a command

cseagle/ida_clemency: IDA cLEMENCy Tools (github.com)

IDA6.8的反汇编脚本。


./clemency-emu -s hello.bin

Middle Endian是此架构比较特殊的地方。

一个字节9比特,第0个比特是左侧最高位。

当从寄存器将数据写入内存时,先存储第9-17比特,再0-8,然后是18-27。

若将一个字节用XX来表示,则

Register XXYYZZ --> Memory YYXXZZ

如果只存储2字节:

Register XXYY --> Memory YYXX

一共32个寄存器;

29个一般寄存器,以R为前缀,27比特,3字节长;同时担任浮点数和整数运算操作;

还有一个单独的标志寄存器FL

同时允许在运算时,将2个任意一般寄存器组合成一个54位的值。

STRAPC寄存器都是特殊寄存器。

R0,通用寄存器,用来存放函数调用时的参数一或返回值的

R1-R8,通用寄存器,存放函数调用的参数二到参数八

R9-R28,通用寄存器,函数调用间保存

ST:编号29,指向保存当前堆栈末尾的内存位置的指针

RA:编号30,返回地址寄存器,由调用指令填充,执行return时使用

PC:编号31,PC寄存器,寄存器只读

FL:flag寄存器

  1. Data Sent Interrupt Enabled
  2. Data Received Interrupt Enabled
  3. Memory Exception Enabled
  4. Divide by 0 Exception Enabled
  5. Invalid Instruction Exception Enabled
  6. Timer4 Interrupt Enabled
  7. Timer3 Interrupt Enabled
  8. Timer2 Interrupt Enabled
  9. Timer1 Interrupt Enabled
  10. Signed bit
  11. Overflow bit
  12. Carry bit
  13. Zero bit

关于栈,由于没有特定的基于堆栈的指令,堆栈没有预期的增长方向,但是在中断期间,处理器将从堆栈指针中减去 99 个字节的数据,将所有寄存器存储到堆栈中,并且中断返回将从中读取 99 个字节当前堆栈指针。如果实现需要将中断添加到堆栈而不是减去,则更改处理器功能区域中的“中断堆栈方向标志( Interrupt stack direction flag )”位将完成此操作。

相对内存索引(Relative memory reference)

所有的相对取址都是从相应指令的开始处计算的。

相对分支(Relative branch)会在不包含分支指令本身大小的情况下调整PC的值;

只有在没跳转的情况下,PC根据分支指令大小调整自己的值。

内存布局/IO

有2个主区域,RAM区域以及DMA映射区域。

程序执行从内存偏移0开始。

所有DMA内存地址的最高位都被设为了1。

这里的16进制数字,每一个1大概是代表了1个9比特的特殊字节。

起始 结束 描述
0000000 3FFFFFF 主程序内存
4000000 400001D 时钟IO
4010000 4010FFF 标志IO
5000000 5001FFF 数据接收
5002000 5002002 数据接收大小
5010000 5011FFF 数据传送
5012000 5012002 数据传送大小
6000000 67FFFFF 共享内存
6800000 6FFFFFF NVRAM内存
7FFFF00 7FFFF1B 中断指针
7FFFF80 7FFFFFF 处理器身份和特征

内存拆分成了1024字节的一页。

每页可以分配4中状态中的1个。

状态 作用
0 不可访问
1 只读
2 读写
3 读执行

常用指令分析

[原创]clemency架构(DEF CON ARCHITECTURE)-CTF对抗-看雪论坛-安全社区|安全招聘|bbs.pediy.com

总体来说的指令是差不多的,其实也就有少量区别。

写到最后发觉整成翻译任务了。

看官方文档,以及SYJ的博客也是很不错的选择。

有空继续翻译。

[[原创]clemency架构(DEF CON ARCHITECTURE)-CTF对抗-看雪论坛-安全社区|安全招聘|bbs.pediy.com](https://bbs.pediy.com/thread-270651.htm#:~:text=cLEMENCy is the LEgitbs Middle ENdian Computer architecture,bit 0 is the left most significant bit.)

Legitimate Business Syndicate: The cLEMENCy Architecture (legitbs.net)

cseagle/ida_clemency: IDA cLEMENCy Tools (github.com)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK