当前位置:   article > 正文

arm svc

arm svc #0x0

隐藏exit,ptrace etc.

C示例

  1. #include <sys/ptrace.h>
  2. #include <stdio.h>
  3. int main()
  4. {
  5. int r;
  6. asm volatile (
  7. "mov r0, #0\n\t" /* PTRACE_TRACEME */
  8. "mov r1, #0\n\t"
  9. "mov r2, #0\n\t"
  10. "mov r3, #0\n\t"
  11. "mov r7, #26\n\t"
  12. "svc #0x00000000\n\t"
  13. "mov %[result], r0"
  14. : [result] "=r" (r)
  15. :
  16. :
  17. );
  18. printf ("Ptrace result : %d\n", r);
  19. test();
  20. while (1);
  21. return 0;
  22. }
  23. void test()
  24. {
  25. int r = ptrace (PTRACE_TRACEME, 0, 0, 0);
  26. printf ("ptrace ret : %d\n", r);
  27. }

运行结果

  1. root@hammerhead:/data/local/tmp # ./a.out
  2. Ptrace result : 0 #asm执行成功
  3. ptrace ret : -1 #ptrace失败,因为已经被attach
  1. root@hammerhead:/ # ps |grep a.out
  2. ps |grep a.out
  3. groot 17282 17273 732 72 00000000 000083cc R ./a.out
  4. root@hammerhead:/ # cat /proc/17282/status
  5. cat /proc/17282/status
  6. Name: a.out
  7. State: R (running)
  8. Tgid: 17282
  9. Pid: 17282
  10. PPid: 17273
  11. TracerPid: 17273 # PTRACE_TRACEME,被父进程跟踪,17282 <- 17273
  12. Uid: 0 0 0 0
  13. Gid: 0 0 0 0

汇编代码比对

  1. .text:0000838C EXPORT test
  2. .text:0000838C test
  3. .text:0000838C
  4. .text:0000838C var_8 = -8
  5. .text:0000838C
  6. .text:0000838C STMFD SP!, {R11,LR}
  7. .text:00008390 ADD R11, SP, #4
  8. .text:00008394 SUB SP, SP, #8
  9. .text:00008398 MOV R0, #0 ; request
  10. .text:0000839C MOV R1, #0
  11. .text:000083A0 MOV R2, #0
  12. .text:000083A4 MOV R3, #0
  13. .text:000083A8 BL ptrace @ 可进行elf GOT Hook
  14. .text:000083AC STR R0, [R11,#var_8]
  15. .text:000083B0 LDR R3, =(aPtraceRetD - 0x83BC)
  16. .text:000083B4 ADD R3, PC, R3 ; "ptrace ret : %d\n"
  17. .text:000083B8 MOV R0, R3 ; format
  18. .text:000083BC LDR R1, [R11,#var_8]
  19. .text:000083C0 BL printf
  20. .text:000083C4 SUB SP, R11, #4
  21. .text:000083C8 LDMFD SP!, {R11,PC}
  22. .text:000083C8 ; End of function test

没有ptrace调用, anti - GOT hook

  1. .text:00008344 main ; DATA XREF: _start+50
  2. .text:00008344 ; .got:main_ptr
  3. .text:00008344
  4. .text:00008344 var_8 = -8
  5. .text:00008344
  6. .text:00008344 STMFD SP!, {R11,LR}
  7. .text:00008348 ADD R11, SP, #4
  8. .text:0000834C SUB SP, SP, #8
  9. .text:00008350 MOV R0, #0
  10. .text:00008354 MOV R1, #0
  11. .text:00008358 MOV R2, #0
  12. .text:0000835C MOV R3, #0
  13. .text:00008360 MOV R7, #0x1A
  14. .text:00008364 SVC 0 @ 通过svc中断调用,无法Hook
  15. .text:00008368 MOV R3, R0
  16. .text:0000836C STR R3, [R11,#var_8]
  17. .text:00008370 LDR R3, =(aPtraceResultD - 0x837C)
  18. .text:00008374 ADD R3, PC, R3 ; "Ptrace result : %d\n"
  19. .text:00008378 MOV R0, R3 ; format
  20. .text:0000837C LDR R1, [R11,#var_8]
  21. .text:00008380 BL printf
  22. .text:00008384
  23. .text:00008384 loc_8384 ; CODE XREF: main:loc_8384
  24. .text:00008384 B loc_8384
  25. .text:00008384 ; End of function main

转载于:https://www.cnblogs.com/gm-201705/p/9863954.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/1013225
推荐阅读
相关标签
  

闽ICP备14008679号