RE-实验吧/逆向观察&bitwise

Aliikas-0x05
题目:
实验吧逆向观察
实验吧 bitwise

1.逆向观察

File 一下 64位ELF。

rev50: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 2.6.24, BuildID[sha1]=695ac65e2d54e1d05b327b59d37c2d6eb6aba299, not stripped

题目叫逆向观察,那我们就直接IDA看一下,进入mian函数,代码如下:

 if ( argc <= 1 )
  {
    puts("usage ./rev50 password");
  }
  else
  {
    src = 'sedecrem';//8315162673632404845LL,按R字符转换一下
    v6 = 0;
    v7 = 0;
    v8 = 0;
    memcpy(&dest, &src, 9uLL);
    for ( i = 0; i <= 999; ++i )
    {
      if ( !strcmp(argv[1], (&dict)[i]) && !strcmp(&dest, (&dict)[i]) )
      {
        puts("Good password ! ");
        goto LABEL_10;
      }
    }
    puts("Bad ! password");
  }
LABEL_10:
  puts(&byte_40252A);

函数说明:

1.memcpy():C 库函数 void *memcpy(void *str1, const void *str2, size_t n)

从存储区 str2 复制 n 个字符到存储区 str1。

2.int strncmp ( const char * str1, const char * str2, size_t n );

若str1与str2的前n个字符相同,则返回0;若s1大于s2,则返回大于0的值;若s1 小于s2,则返回小于0的值。

那要打印出Good password,那不就应该让!strcmp(argv[1], (&dict)[i]) && !strcmp(&dest, (&dict)[i])都为1嘛,那我们输入的就应该和dest一样…真的有这么简单吗?

./rev50 sedecrem
Bad ! password

emmmmmm这里我就想到了,储存方式的不同(大小端问题),故直接把字符串反转一下:

./rev50 mercedes
Good password !

2.bitwise

题目给出了python代码,如下:

    user_submitted = raw_input("Enter Password: ")
    
    if len(user_submitted) != 10:
      print "Wrong"
      exit()
    
    
    verify_arr = [193, 35, 9, 33, 1, 9, 3, 33, 9, 225]
    user_arr = []
    for char in user_submitted:
      # '<<' is left bit shift
      # '>>' is right bit shift
      # '|' is bit-wise or
      # '^' is bit-wise xor
      # '&' is bit-wise and
      user_arr.append( (((ord(char) << 5) | (ord(char) >> 3)) ^ 111) & 255 )
    
    if (user_arr == verify_arr):
      print "Success"
    else:
      print "Wrong"

那直接写出解密算法即可,这题不是很难0.0

s = [193, 35, 9, 33, 1, 9, 3, 33, 9, 225]
key=[0,0,0,0,0,0,0,0,0,0]
for i in range(10):
    for j in range(128):
        if s[i]==(((j<< 5) | (j >> 3)) ^ 111) & 255 :
            key[i]=chr(j)
        
flag= ''
for i in key:
    flag+=i
print flag

得:ub3rs3cr3t

补充:Big-Endian和Little-Endian的定义如下:

1) Little-Endian就是低位字节排放在内存的低地址端,高位字节排放在内存的高地址端。
2) Big-Endian就是高位字节排放在内存的低地址端,低位字节排放在内存的高地址端。
举一个例子,比如数字0x12 34 56 78在内存中的表示形式为:
1)大端模式:

低地址高地址
0x120x340x560x78

2)小端模式:

低地址高地址
0x780x560x340x12

可见,大端模式和字符串的存储模式类似。

3)下面是两个具体例子:

16bit宽的数0x1234在Little-endian模式(以及Big-endian模式)CPU内存中的存放方式(假设从地址0x4000开始存放)为:

内存地址小端模式存放内容大端模式存放内容
0x40000x340x12
0x40010x120x34

·32bit宽的数0x12345678在Little-endian模式以及Big-endian模式)CPU内存中的存放方式(假设从地址0x4000开始存放)为:

内存地址小端模式存放内容大端模式存放内容
0x4000x780x12
0x40010x560x34
0x40020x340x56
0x40030x120x78

4)大端小端没有谁优谁劣,各自优势便是对方劣势:

小端模式 :强制转换数据不需要调整字节内容,1、2、4字节的存储方式一样。
大端模式 :符号位的判定固定为第一个字节,容易判断正负。

三、数组在大端小端情况下的存储:
  以unsigned int value = 0x12345678为例,分别看看在两种字节序下其存储情况,我们可以用unsigned char buf[4]来表示value:
  Big-Endian: 低地址存放高位,如下:

高地址
buf[3] (0x78)低位
buf[2] (0x56)
buf[1] (0x34)
buf[0] (0x12)高位
低地址

Little-Endian: 低地址存放低位,如下:

高地址
buf[3] (0x12)高位
buf[2] (0x34)
buf[1] (0x56)
buf[0] (0x78)低位
低地址

总结:题略水0.0,但还是锻炼了自己的逆向思维和写脚本的能力
参考资料:https://blog.csdn.net/ce123_zhouwei/article/details/6971544

"/pkg/qct/software/llvm/release/arm/14.0.0/bin/clang" -g -Os -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -c -include AutoGen.h -mlittle-endian -fno-short-enums -save-temps -fverbose-asm -funsigned-char -ffunction-sections -fdata-sections -fno-builtin -Wno-address -fno-asynchronous-unwind-tables -target aarch64-linux-gnu -fcolor-diagnostics -fdiagnostics-format=vi -Wno-parentheses-equality -Wno-tautological-compare -Wno-tautological-constant-out-of-range-compare -Wno-empty-body -Wno-unknown-warning-option -Wno-unused-function -Wno-bitwise-op-parentheses -mcmodel=small -ffixed-x18 -mstrict-align -fstack-protector -Wno-nonportable-include-path -Wno-misleading-indentation -fno-common -mtune=cortex-a53 -I/home/chen-docker/bin/boot/boot_images/BuildLogs/QcomPkg/SocPkg/LeMans/AU/Include -include /home/chen-docker/bin/boot/boot_images/boot/QcomPkg/Include/Library/DebugLib.h -DQCOM_EDK2_PATCH -DDISABLE_DEP -DENABLE_XN -DENABLE_ASLR -DENABLE_DEP_64 -DENABLE_EXEC_CODE_READY_TO_BOOT -DENABLE_AUTO_PLAT -DMAX_DDR_REGIONS=6 -mstrict-align -mcpu=cortex-a53 -DPRODMODE -c -o /home/chen-docker/bin/boot/boot_images/Build/LeMansAU/Core/RELEASE_CLANG140LINUX/AARCH64/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib/OUTPUT/./HiiLib.obj @/home/chen-docker/bin/boot/boot_images/Build/LeMansAU/Core/RELEASE_CLANG140LINUX/AARCH64/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib/OUTPUT/inc.lst /home/chen-docker/bin/boot/boot_images/edk2/MdeModulePkg/Library/UefiHiiLib/HiiLib.c /pkg/qct/software/llvm/release/arm/14.0.0/bin/clang: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory GNUmakefile:373: recipe for target '/home/chen-docker/bin/boot/boot_images/Build/LeMansAU/Core/RELEASE_CLANG140LINUX/AARCH64/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib/OUTPUT/HiiLib.obj' failed Building ... /home/chen-docker/bin/boot/boot_images/edk2/MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf [AARCH64] make: *** [/home/chen-docker/bin/boot/boot_images/Build/LeMansAU/Core/RELEASE_CLANG140LINUX/AARCH64/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib/OUTPUT/HiiLib.obj] Error 127 make: Nothing to be done for 'tbuild'. build.py... : error 7000: Failed to execute command make tbuild [/home/chen-docker/bin/boot/boot_images/Build/LeMansAU/Core/RELEASE_CLANG140LINUX/AARCH64/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib]错误在哪里?
最新发布
07-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值