Upgrade to Pro — share decks privately, control downloads, hide ads and more …

linux_10.pdf

Yosuke Furukawa
July 30, 2015
29

 linux_10.pdf

Yosuke Furukawa

July 30, 2015
Tweet

Transcript

  1. γεςϜίʔϧͷೖޱͱग़ޱ • γεςϜίʔϧ͸2ͭͷೖޱͱग़ޱ͕͋Δɻ • Intel pentium 2 Ҏલͷݹ͍ํ๏ • ೖޱ:

    int $0x80 ग़ޱ: iret • Intel pentium 2 Ҏ߱ͷ৽͍͠ํ๏ ͋ͱ ARM΋ͬͪ͜ • ೖޱ: sysenter ग़ޱ: sysexit
  2. Ҿ਺ड͚౉͠ • Q.͡Ό͋Ͳ͜ʹ٧Ή͔? • A. Ϩδελ • eax (γεςϜίʔϧ൪߸͕֨ೲ͞ΕΔ, γες

    ϜίʔϧຖʹҰҙͳ൪߸ ※ ausyscall ͰݟΕΔ) • ebx, ecx, edx, esi, edi, ebp (Ҿ਺༻ʹ࢖ΘΕΔ) FBY FCY FEY FTJ
  3. Ҿ਺ड͚౉͠ • େࡶ೺ͳ֬ೝͩͱϓϩηεۭؒʹଐ͍ͯ͠Δ ͔ΛνΣοΫͰ͖ͳ͍ • ͨͩͬ͘͟Γͨ͠νΣοΫ͸Ͱ͖Δɻ͜ΕͰ ࣮ࡍͷνΣοΫΛ஗ԆධՁ͍ͯ͠Δɻ JOUBDDFTT@PL DPOTUWPJE BEES

    VOTJHOFEMPOHTJ[F \ VOTJOHFEMPOHB VOTJOHOFEMPOH BEES JG B TJ[FBccB TJ[FDVSSFOU@UISFBE@JOGP BEES@MJNJUTFH  SFUVSO SFUVSO ^
  4. Ҿ਺ड͚౉͠ • େࡶ೺ͳ֬ೝͩͱϓϩηεۭؒʹଐ͍ͯ͠Δ ͔ΛνΣοΫͰ͖ͳ͍ • ͨͩͬ͘͟Γͨ͠νΣοΫ͸Ͱ͖Δɻ͜ΕͰ ࣮ࡍͷνΣοΫΛ஗ԆධՁ͍ͯ͠Δɻ JOUBDDFTT@PL DPOTUWPJE BEES

    VOTJHOFEMPOHTJ[F \ VOTJOHFEMPOHB VOTJOHOFEMPOH BEES JG B TJ[FBccB TJ[FDVSSFOU@UISFBE@JOGP BEES@MJNJUTFH  SFUVSO SFUVSO ^ 2^32 - 1 Λ௒͔͑ͨͲ͏͔
  5. Ҿ਺ड͚౉͠ • େࡶ೺ͳ֬ೝͩͱϓϩηεۭؒʹଐ͍ͯ͠Δ ͔ΛνΣοΫͰ͖ͳ͍ • ͨͩͬ͘͟Γͨ͠νΣοΫ͸Ͱ͖Δɻ͜ΕͰ ࣮ࡍͷνΣοΫΛ஗ԆධՁ͍ͯ͠Δɻ JOUBDDFTT@PL DPOTUWPJE BEES

    VOTJHOFEMPOHTJ[F \ VOTJOHFEMPOHB VOTJOHOFEMPOH BEES JG B TJ[FBccB TJ[FDVSSFOU@UISFBE@JOGP BEES@MJNJUTFH  SFUVSO SFUVSO ^ ΧϨϯτεϨουͷϦϛοτΛ௒͔͑ͨͲ͏͔ ΧʔωϧϞʔυͷ࣌͸0xfffffff ී௨ͷϓϩηε͸ PAGE_OFFSET - 1
  6. Χʔωϧϥούʔϧʔνϯ • ϥΠϒϥϦؔ਺ʹͳ͍ͬͯͳ͍γεςϜίʔϧΛݺͼग़͢͜ͱ͕Ͱ ͖Δɻ • _syscall0 ~ _syscall6 ·Ͱ͋Δ(Ҿ਺ͷݸ਺෼) •

    CϥΠϒϥϦʹͳ͍ͬͯͳ͍΋ͷ΋ݺ΂Δɻ • ͨͩ͠ࠓ͸ଘࡏ͠ͳ͍?? • manΛௐ΂Δͱ syscall Λ࢖͑ͬͯͳͬͯΔɻ
 http://linuxjm.osdn.jp/html/LDP_man-pages/man2/_syscall.2.html
  7. Χʔωϧϥούʔϧʔνϯ #include <unistd.h> int main( int argc, char *argv[ ]

    ) { int err; const char *text = “Hello World\n"; write( STDOUT_FILENO, ( const void* )text, sizeof( text ) - 1 ); return( 0 ); } ී௨൛
  8. Χʔωϧϥούʔϧʔνϯ #include <unistd.h> #include <sys/syscall.h> int main( int argc, char

    *argv[ ] ) { long ret; const char *text = “Hello World\n"; ret = syscall( SYS_write, STDOUT_FILENO, text, sizeof( text ) - 1 ); return( 0 ); } Χʔωϧϥούʔϧʔνϯ࢖ͬͨ൛
  9. ͓·͚ • γεςϜίʔϧݺͼग़͠͸ݟͯ΋Βͬͨͱ͓ΓOSʹͱͬͯ͸ෛՙͷ͔͔ΔॲཧʢϨδελୀ ආɺҾ਺౉͠νΣοΫɺϞʔυมߋetc etcʣ • ଟ༻͗͢͠Δͷ͸ྑ͘ͳ͍ɻΪϦΪϦ·ͰϢʔβʔϞʔυͰؤுͬͯ࠷ޙʹγεςϜίʔϧ͕ ͱΓ͋͑ͣమଇ(ͱ͍͏ͷΛΑ͘ݟ͔͚ͨ) • mTCPͱ͔ͦ͏͍͏ࢥ૝ͬΆ͍

    • http://www.slideshare.net/hajimetazaki/mtcp-34743298 • https://github.com/eunyoung14/mtcp • ͨͩsyscalls͕ѱ͍͍ͬͯ͏࿩ΑΓ୯७ʹFile I/OόοϑΝͪΌΜͱ͠Α͏Ͷ͍ͬͯ͏࿩ͷ͕ଟ ͍ͷͰӏವΈʹͯ͠͸͍͚ͳ͍ • http://www.atmarkit.co.jp/ait/articles/1112/13/news117.html (͍ͩͿ࣌ؒΛແବʹͨ͠)