phrack 문서를 분석하다가... 바이너리 코드를 어떻게 어셈으로 아무렇지도 않게 설명하는지...

parkys1의 이미지

전 지금 phrack 63호 hacking the grub for fun and profit 을 보고 있습니다

http://www.phrack.org/archives/63/p63-0x0a_Hacking_Grub.txt

헌데 여기서 보다보니 중간에 hexdump를 이용해서 컴파일된 어셈 코드를 보는 부분이 있습니다.

# hexdump -x -n 512 /boot/grub/stage2
    ...
00001d0  [ 0000    0000    0000    0000 ][ 0000    0000    0000    0000 ]
00001e0  [ 62c7    0026    0064    1600 ][ 62af    0026    0010    1400 ]
00001f0  [ 6287    0026    0020    1000 ][ 61d0    0026    003f    0820 ]
 
    We should interpret(backwards) it as: load 0x3f sectors(start with No.
0x2661d0) to 0x0820:0000, load 0x20 sectors(start with No.0x266287) to
0x1000:0000, load 0x10 sectors(start with No.0x2662af) to 0x1400:00, load
0x64 sectors(start with No.0x2662c7) to 0x1600:0000. 

이 부분은 앞에서 stage2의 512바이트를 읽고(start.S) start.S가 stage2의 나머지 부분을 읽는 부분입니다. 문서에서 보니 섹터 넣는 부분은 자동으로 설치시에 변경된다는 것입니다.

여기서 어떻게 003f 0820 이 load 0x3f sectors to 0x0820:0000 으로 해석되죠?
어셈 명령이 바이너리 코드로 해석되는가요? 흠...
그리고 start with No. 0x2661d0 이것은 뭘 의미하는지 모르겠습니다 ㅡㅡ;
나머지도 다 그런식으로 되어있네요 ㅡㅡ; 설명해야하는데 어떻게 해야할지 ㅡㅡ;
아참 그리고 인스톨 할 때 0x3f 가 다음 섹터라는거 어떻게 알아내죠? 흠...

그럼 고수분들 답변 부탁 드립니다.

grassman의 이미지

바로 위에 BEGIN - END 사이에 데이터 구조가 나와 있네요.

blocklist_default_start:
.long 2 /* this is the sector start parameter, in logical
sectors from the start of the disk, sector 0 */
blocklist_default_len: /* this is the number of sectors to read */
.word (STAGE2_SIZE + 511) >> 9
blocklist_default_seg:
.word 0x820 /* this is the segment of the starting address
to load the data into */
firstlist: /* this label has to be after the list data!!! */

처음에 나오는 blocklist_default_start가 4바이트고 읽기 시작할 logical sector 번호를 지정한다고 주석이 달려있죠. 그 다음에는 2바이트 크기의 읽을 섹터 수와 2바이트 크기의 세그먼트 주소가 나온다고 적혀 있습니다.

그대로 해석해 보면 [61d0 0026 003f 0820]은 61d0 0026, 003f, 0820으로 나눠지죠.
61d0 0026은 little endian을 기준으로 해석하면 0x002661d0입니다. 시작 섹터는 0x002661d0에 읽을 섹터 수는 0x3f, 읽은 데이터를 저장할 세그먼트:옵셋 주소는 0820:0000h가 되는 거죠.

phrack 문서를 보실 때는 차분히 읽어보시기 바랍니다. 적어도 배경지식이 모자라지 않는다면 이해할 수 있는 수준의 문서니까요.

ssehoony의 이미지

grassman wrote:

적어도 배경지식이 모자라지 않는다면 이해할 수 있는 수준의 문서니까요.

모든 문서가 다 그렇습니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.