首页
社区
课程
招聘
[原创]看雪.京东 2018CTF 第十五题 智能设备 Writeup
2018-7-14 20:08 2766

[原创]看雪.京东 2018CTF 第十五题 智能设备 Writeup

2018-7-14 20:08
2766

#看雪.京东 2018CTF 第十五题 智能设备 Writeup

此题用qemu模拟了vexpress-a9开发板,使用自写程序作为shell的身份验证手段。

试运行

因为不知道考题在哪,所以上来先试运行。

...
please input your key:1111111
your key is error
please input your key

内核启动结束后,就出现输入key的提示,要求验证。

寻找验证bin

题目意思已经很明了,进系统要求验证,可能这就是key吧。下一步就是寻找这个验证功能的bin文件了。
先查看文件系统:

$ file a9rootfs
a9rootfs: Linux rev 1.0 ext3 filesystem data, UUID=d8a4bf4a-95c3-4cba-9893-827cd9e120fd (needs journal recovery) (large files)

直接挂载文件系统。

$sudo mount -t ext3  a9rootfs ./rootfs
$tree -L 1 rootfs
rootfs
├── bin
├── dev
├── lib
├── linuxrc
├── lost+found
├── sbin
└── usr

竟然没有/etc,那linuxrc过后是直接调shell了吧。
/bin下的shell果然已经被换了成了bin,而不是指向busybox的link。
确认下:

$ strings sh | grep "your key"
please input your key:

验证算法分析及解算

最主要部分的算法伪代码如下:

  scanf("%100s", &input);
  length = strlen(&input);
  multi_and_add_1f((char *)&input, str1, length);
  hex_trans((int)&input, (int)&str2, length);
  hex_normal((char *)&str2, out, length);       // 0123456789ABCDEF
  if ( !strcmp(out, "C1371DA51A9030079E21DCDC5B78E38563872139C13F6F") )
  {
    unhex_normal(v5, "5B7B541D49541B0847551A16435D060D0A66", 18);
    swap_and_xor(v5, 18);                       // flag:you got it [
    hex_trans((int)str1, (int)&str2, length);
    hex_normal((char *)&str2, str1, length);
    print((int)"%s%s%c\n", v5, str1, ']');
  }



signed int __fastcall hex_trans(int a1, int a2, signed int a3)
{
  signed int result; // r0
  int v4; // [sp+4h] [bp-118h]
  char *v5; // [sp+8h] [bp-114h]
  char v6; // [sp+14h] [bp-108h]
  int v7; // [sp+114h] [bp-8h]

  v5 = (char *)a2;
  v4 = a3;
  v7 = g_cookie;
  if ( a3 > 128 )
    v4 = 128;
  memcpy((_BYTE *)a2, a1, v4, v4);
  hex_1(v5, &v6, v4);                           // FDB08642ECA97531
  unhex_2(v5, &v6, v4);                         // 13579BDF02468ACE
  swap_and_xor(v5, v4);
  hex_3(v5, &v6, v4);                           // 0369CF258BE147AD
  unhex_4(v5, &v6, v4);                         // FA50B61C72D83E94
  swap_and_xor(v5, v4);
  hex_1(v5, &v6, v4);
  unhex_4(v5, &v6, v4);
  swap_and_xor(v5, v4);
  hex_3(v5, &v6, v4);
  unhex_2(v5, &v6, v4);
  swap_and_xor(v5, v4);
  result = 1;
  if ( v7 != g_cookie )
    check_cookie_fail();
  return result;
}

主要涉及不同16进制表示数的转换、逆序和异或计算。

 

算法比较简单,可见下面的云计算脚本:

def my_hex(str,table):
  s = ''
  for i in str:
    l = ord(i)&0x0f
    h = (ord(i)&0xf0)>>4
    s += table[h]+table[l]
  return s

def my_unhex(str,table):
  s = ''
  for i in range(len(str)/2):
#    print str[2*i],str[2*i+1]
    h = table.index(str[2*i])
    l = table.index(str[2*i+1])
    s += chr(16*h+l)
  return s

def de_xor(str):
  s = str[0]

  for i in range(1,len(str)):
    s += chr(ord(str[i-1])^ord(str[i]))
  return s[::-1]

def en_xor(str):
  str = str[::-1]
  s = str[0]  
  for i in range(1,len(str)):
    s += chr(ord(s[i-1])^ord(str[i]))
  return s

table1 = '0123456789ABCDEF'
table2 = 'FDB08642ECA97531'
table3 = '13579BDF02468ACE'
table4 = '0369CF258BE147AD'
table5 = 'FA50B61C72D83E94'


print my_hex('1234',table1)
t = 'C1371DA51A9030079E21DCDC5B78E38563872139C13F6F'
#t = '2A20D1EE7374B49EE12BCB5809A19'
#t = '8D8A79E3749EBA060E57D00A6A'
ss = my_unhex(t,table1)
ss = de_xor(ss)
ss = my_hex(ss,table3)
ss = my_unhex(ss,table4)
ss = de_xor(ss)
ss = my_hex(ss,table5)
ss = my_unhex(ss,table2)
ss = de_xor(ss)
ss = my_hex(ss,table5)
ss = my_unhex(ss,table4)
ss = de_xor(ss)
ss = my_hex(ss,table3)
ss = my_unhex(ss,table2)
print ss
print en_xor('5B7B541D49541B0847551A16435D060D0A66'.decode('hex'))
print en_xor('721D1D001745531A49591C0E4B52071A1679'.decode('hex'))

得到输入值为2018ctf0520pediy1314yyp。输入后程序输出如下:

please input your key:2018ctf0520pediy1314yyp
flag:you got it [B1732120572455BAFD30F062F9C49A8A996A8A9DDB4283]
you have a chance to exploit it:

似乎后面还可以玩,没有深究。

 

所以最终flag为:B1732120572455BAFD30F062F9C49A8A996A8A9DDB4283


[培训]《安卓高级研修班(网课)》月薪三万计划,掌 握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

收藏
免费 2
打赏
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回