Git Product home page Git Product logo

Comments (7)

sangkilc avatar sangkilc commented on May 2, 2024 1

Object파일에 있는 변수들의 대한 주소를 지금 이야기 하고 있는 것이고, 따라서 실제 linking된 이후에는 그 주소가 달라질 수 밖에 없습니다. 따라서 gdb나 다른 툴에서는 해당 변수가 속하는 섹션의 파일 오프셋을 기반으로 임의의 주소를 부여한 것에 불과합니다. 예를 들면 main_arena의 경우에는 .data 섹션에 속하기 때문에 파일상에서 .data섹션의 위치는 0x6a50이고, .text섹션의 경우 0x40 부터 시작하기 때문에, .text섹션의 주소를 0으로 간주하고, .data섹션의 위치를 0x6a10으로 간주한 것 입니다. 하지만, 실제 링킹시에는 ,text섹션과 .data섹션의 위치가 변동될 수 있기 때문에 올바른 주소라고 볼 수 없습니다. 실제로 해당 파일의 .data 섹션의 주소는 0번지로 맵핑되어 있기도 하고, 여기서는 주소가 의미가 없기 때문에 이 문제를 버그라고 보기는 좀 어렵습니다.

하지만, 가상의 주소를 다른 툴과 동일한 휴리스틱을 적용해 계산하는 것은 역공학 측면에서 의미있는 일이라 판단되고, 따라서 이 이슈는 유효한 feature request라고 판단됩니다.

from b2r2.

sangkilc avatar sangkilc commented on May 2, 2024

리포트 고맙습니다. 정확히 어떤 함수/심볼에 대한 주소가 잘못되었다는 것인지 명확히 해주실 수 있을까요?

from b2r2.

sangkilc avatar sangkilc commented on May 2, 2024

그림으로 짐작해 볼때,
main_arena의 주소가 0인 부분이 잘못되었다고 말씀하신 것 같지만, 0이 맞습니다. 6A10 은 단순히 파일 오프셋일 뿐이고 실제 심볼의 주소는 0이 들어가 있는게 맞습니다. object파일이기 때문에 relocation이전의 심볼은 당연히 0이 맞습니다. readelf를 통해 심볼 값을 보더라도 다음과 같이 나옵니다:

107: 0000000000000000  2184 OBJECT  LOCAL  DEFAULT    3 main_arena

다른 심볼 역시 마찬가지 입니다. 따라서 버그가 아닙니다.

from b2r2.

cha5126568 avatar cha5126568 commented on May 2, 2024

해당함수의 Address는 RVA주소값을 나타내는 것이 아닌가요?
(레퍼런스가 없어서 조금 망설여지지만, 맞다고 가정하고 게속 이야기 하겠습니다. 아니라면 죄송합니다..ㅜㅜ)

readelf 의 --symbols 옵션은 심볼테이블의 정보를 보여주는것이라 그렇게 나오지만, 실제 relocation 이전의 주소는 그렇지 않습니다. 아래 두 경우를 봐주세요.

root@ubuntu:/tmp# gdb -q ./malloc.o
Reading symbols from ./malloc.o...(no debugging symbols found)...done.
(gdb) p &global_max_fast
$1 = (<data variable, no debug info> *) 0x7328 <global_max_fast>
(gdb) p &main_arena
$2 = (<data variable, no debug info> *) 0x6a10 <main_arena>
(gdb) p &malloc_init_state
$3 = (<text variable, no debug info> *) 0x0 <malloc_init_state>

실제 메모리상에서도 main_arena 가 0x6a10 위치에 위치합니다.

또 angr의 symbol을 얻어오는 기능도 아래와 같이 동작합니다.

import cle

p = cle.loader.Loader("malloc.o")
malloc_init_state = p.main_object.get_symbol("malloc_init_state")
main_arena = p.main_object.get_symbol("main_arena")
global_max_fast = p.main_object.get_symbol("global_max_fast")

print (hex(malloc_init_state.relative_addr))
print (hex(main_arena.relative_addr))
print (hex(global_max_fast.relative_addr))
0x0
0x6a10
0x7328

따라서 GetSymbols 함수가 Symbol Table의 정보를 그대로 가져오는것이 아니라, RVA값을 가져오는 목적이라면(실제 제가 b2r2를 활용하려고 하는 상황도 이 상황이고, 이 상황이 일반적일 것 같습니다.) 버그가 맞다고 생각합니다.

from b2r2.

sangkilc avatar sangkilc commented on May 2, 2024

Fixed by 2bb21d6

from b2r2.

cha5126568 avatar cha5126568 commented on May 2, 2024

수정 감사합니다!

다만, 2bb21d6 커밋 이후로, 일부파일에서 다른 도구들과 다른 값을 반환합니다.
아래 경우를 봐주세요.
(문제가 되는 파일은 여기 에서 다운로드 받으실 수 있습니다.)

0.2.1 release

latest

cutter(r2) / IDA

기존(0x39a1c0) 과 다르게 BSS섹션의 VA가 한번 더 더해진 값(0x7330a0)을 반환합니다.

0x7330a0-0x39a1c0=0x398ee0 이고, 이 파일에서 bss의 베이스가 0x398ee0 입니다. 저 커밋 이후로 잘못된 값을 반환하는 것 같습니다.

from b2r2.

sangkilc avatar sangkilc commented on May 2, 2024

Should be fixed by 4ba0b98

from b2r2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.