ebook img

Sockets, Shellcode, Porting, and Coding: Reverse Engineering Exploits and Tool Coding for Security Professionals PDF

784 Pages·2005·3.4 MB·Russian
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Sockets, Shellcode, Porting, and Coding: Reverse Engineering Exploits and Tool Coding for Security Professionals

Äæåéìñ Ñ. Ôîñòåð ïðè ó÷àñòèè Ìàéêà Ïðàéñà Защита от взлома: сокеты, эксплойты, shеll(cid:19)код Серия «Информационная безопасность» Москва УДК 004.2 ББК 32.973.26(cid:6)018.2 Ф81 Ф81 ÄÄÄÄÄæææææåååååéééééìììììñññññ ÔÔÔÔÔîîîîîñññññòòòòòåååååððððð,,,,, ïïïïïðððððèèèèè óóóóó÷÷÷÷÷àààààñññññòòòòòèèèèèèèèèè ÌÌÌÌÌàààààéééééêêêêêààààà ÏÏÏÏÏðððððàààààéééééñññññààààà Защита от взлома: сокеты, эксплойты, shell(cid:20)код: Пер. с англ. Слинкина А. А. – М.: Издательский Дом ДМК(cid:20)пресс.– 784 с.: ил. ISBN 5(cid:6)9706(cid:6)0019(cid:6)9  ñâîåé íîâîé êíèãå Äæåéìñ Ôîñòåð, àâòîð ðÿäà áåñòñåëëåðîâ, âïåð- âûå îïèñûâàåò ìåòîäû, êîòîðûìè ïîëüçóþòñÿ õàêåðû äëÿ àòàê íà îïå- ðàöèîííûå ñèñòåìû è ïðèêëàäíûå ïðîãðàììû. Îí ïðèâîäèò ïðèìåðû ðàáîòàþùåãî êîäà íà ÿçûêàõ C/C++, Java, Perl è NASL, â êîòîðûõ èëëþ- ñòðèðóþòñÿ ìåòîäû îáíàðóæåíèÿ è çàùèòû îò íàèáîëåå îïàñíûõ àòàê.  êíèãå ïîäðîáíî èçëîæåíû âîïðîñû, ðàçáèðàòüñÿ â êîòîðûõ íàñóùíî íåîáõîäèìî ëþáîìó ïðîãðàììèñòó, ðàáîòàþùåìó â ñôåðå èíôîðìà- öèîííîé áåçîïàñíîñòè: ïðîãðàììèðîâàíèå ñîêåòîâ, shell-êîäû, ïåðåíî- ñèìûå ïðèëîæåíèÿ è ïðèíöèïû íàïèñàíèÿ ýêñïëîéòîâ УДК 004.2 ББК 32.973.26(cid:20)018.2 Original English language edition published by Syngress Publishing, Inc. Copyright © 2005 by Syngress Publishing, Inc. All rights reserved. Все права защищены. Любая часть этой книги не может быть воспроизведена в какой бы то ни было форме и какими бы то ни было средствами без письменного разрешения вла(cid:20) дельцев авторских прав. Материал, изложенный в данной книге, многократно проверен. Но поскольку вероятность технических ошибок все равно существует, издательство не может гарантировать абсолютную точность и правильность приводимых сведений. В связи с этим издательство не несет ответ(cid:20) ственности за возможные ошибки, связанные с использованием книги. ISBN 1-597490-05-9 (àíãë.) Copyright © by Syngress Publishing, Inc. ISBN 5-9706-0019-9 © Ïåðåâîä íà ðóññêèé ÿçûê, îôîðìëåíèå, èçäàíèå, Èçäàòåëüñêèé Äîì ÄÌÊ-ïðåññ Содержание Благодарности ......................................................................................... 23 Об авторе ................................................................................................. 24 Об основном соавторе............................................................................ 25 Прочие соавторы, редакторы и авторы кода..................................... 26 Об авторе предисловия.......................................................................... 28 Предисловие............................................................................................. 29 Íàñòóïèò ëè «ñóäíûé äåíü»?.............................................................................29 Глава 1. Написание безопасных программ......................................... 31 Ââåäåíèå...............................................................................................................32 C/C++....................................................................................................................33 Õàðàêòåðèñòèêè ÿçûêà......................................................................................34 ßçûê C........................................................................................................34 ßçûê C++....................................................................................................35 Áåçîïàñíîñòü...............................................................................................35 Ïðèìåð «Çäðàâñòâóé, ìèð!».............................................................................36 Òèïû äàííûõ....................................................................................................37 Ïîòîê óïðàâëåíèÿ...........................................................................................40 Ôóíêöèè ...........................................................................................................41 Êëàññû (òîëüêî C++).......................................................................................42 Ïðèìåð: ðÿäû Ôóðüå .......................................................................................44 ßçûê Java..............................................................................................................48 Õàðàêòåðèñòèêè ÿçûêà......................................................................................49 Îáúåêòíî-îðèåíòèðîâàííûå âîçìîæíîñòè..............................................49 Ïëàòôîðìåííàÿ íåçàâèñèìîñòü.................................................................49 Ìíîãîïîòî÷íîñòü.......................................................................................49 Áåçîïàñíîñòü...............................................................................................50 Äîïîëíèòåëüíûå âîçìîæíîñòè .................................................................50 Ïðèìåð «Çäðàâñòâóé, ìèð!».............................................................................50 Òèïû äàííûõ....................................................................................................51 Ïîòîê óïðàâëåíèÿ...........................................................................................52 Ìåòîäû.............................................................................................................54 6 Защита от взлома: сокеты, эксплойты и shell#код Êëàññû...............................................................................................................54 Ïîëó÷åíèå çàãîëîâêîâ HTTP............................................................................57 ßçûê C#................................................................................................................59 Îñíîâàíèÿ äëÿ ïåðåõîäà íà C#.........................................................................59 Õàðàêòåðèñòèêè ÿçûêà......................................................................................60 Îáúåêòíî-îðèåíòèðîâàííûå âîçìîæíîñòè..............................................60 Ïðî÷èå âîçìîæíîñòè.................................................................................61 Áåçîïàñíîñòü...............................................................................................61 Ïðèìåð «Çäðàâñòâóé, ìèð!» íà ÿçûêå C# ........................................................62 Òèïû äàííûõ....................................................................................................62 Ïîòîê óïðàâëåíèÿ...........................................................................................64 Ìåòîäû.............................................................................................................66 Êëàññû...............................................................................................................66 Ïîòîêè â ÿçûêå C#...........................................................................................69 Ïðèìåð: ðàçáîð IP-àäðåñà, çàäàííîãî â êîìàíäíîé ñòðîêå...........................70 ßçûê Perl..............................................................................................................79 Òèïû äàííûõ....................................................................................................80 Îïåðàòîðû........................................................................................................82 Ïðèìåð Perl-ñöåíàðèÿ......................................................................................84 Àíàëèç.........................................................................................................85 Ñïåöèàëüíûå ïåðåìåííûå..............................................................................86 Ñîïîñòàâëåíèå ñ îáðàçöîì è ïîäñòàíîâêà......................................................87 Ìîäèôèêàòîðû ðåãóëÿðíûõ âûðàæåíèé ........................................................88 Êàíîíè÷åñêèå èíñòðóìåíòû, íàïèñàííûå íà Perl..........................................88 ß óìåþ ïèñàòü íà Perl!......................................................................................89 Êàíîíè÷åñêàÿ àòàêà íà Web-ñåðâåð ............................................................89 Àíàëèç.........................................................................................................90 Óòèëèòà ìîäèôèêàöèè ôàéëà ïðîòîêîëà.........................................................90 Ðåçóëüòàò âûïîëíåíèÿ................................................................................93 Àíàëèç.........................................................................................................94 ßçûê Python ........................................................................................................96 Ïàêåò InlineEgg.................................................................................................96 Àíàëèç.........................................................................................................98 Àíàëèç.........................................................................................................99 Ðåçþìå ................................................................................................................101 Îáçîð èçëîæåííîãî ìàòåðèàëà .....................................................................103 Ññûëêè íà ñàéòû................................................................................................104 ×àñòî çàäàâàåìûå âîïðîñû............................................................................105 Содержание 7 Глава 2. Язык сценариев NASL ............................................................ 107 Ââåäåíèå.............................................................................................................108 Èñòîðèÿ ..........................................................................................................108 Íàçíà÷åíèå NASL..........................................................................................109 Ïðîñòîòà è óäîáñòâî ................................................................................109 Ìîäóëüíîñòü è ýôôåêòèâíîñòü................................................................109 Áåçîïàñíîñòü.............................................................................................110 Îãðàíè÷åíèÿ NASL...................................................................................110 Ñèíòàêñèñ ÿçûêà NASL.....................................................................................110 Êîììåíòàðèè............................................................................................110 Ïðèìåð ïðàâèëüíîãî êîììåíòàðèÿ...................................................110 Ïðèìåðû íåïðàâèëüíûõ êîììåíòàðèåâ ............................................111 Ïåðåìåííûå..............................................................................................111 Öåëûå ÷èñëà.........................................................................................111 Ñòðîêè..................................................................................................111 Ìàññèâû...............................................................................................111 NULL....................................................................................................113 Áóëåâñêèå âåëè÷èíû ...........................................................................113 Îïåðàòîðû ................................................................................................113 Îïåðàòîðû âíå êàòåãîðèè ..................................................................113 Îïåðàòîðû ñðàâíåíèÿ.........................................................................114 Àðèôìåòè÷åñêèå îïåðàòîðû ..............................................................114 Îïåðàòîðû ðàáîòû ñî ñòðîêàìè ........................................................115 Ëîãè÷åñêèå îïåðàòîðû........................................................................115 Ïîáèòîâûå îïåðàòîðû........................................................................116 Îïåðàòîðû ñîñòàâíîãî ïðèñâàèâàíèÿ â ñòèëå C...............................116 Óïðàâëÿþùèå êîíñòðóêöèè.....................................................................117 Èíñòðóêöèè if.......................................................................................117 Öèêëû for..............................................................................................117 Öèêëû foreach.......................................................................................118 Öèêëû while.........................................................................................118 Öèêëû repeat-until...............................................................................118 Èíñòðóêöèÿ break................................................................................118 Ïîëüçîâàòåëüñêèå ôóíêöèè ...............................................................119 Âñòðîåííûå ôóíêöèè..........................................................................120 Èíñòðóêöèÿ return...............................................................................120 Íàïèñàíèå ñöåíàðèåâ íà ÿçûêå NASL ..........................................................120 Íàïèñàíèå ñöåíàðèåâ äëÿ ëè÷íîãî ïîëüçîâàíèÿ ........................................121 Ñåòåâûå ôóíêöèè.....................................................................................121 Ôóíêöèè, ñâÿçàííûå ñ ïðîòîêîëîì HTTP................................................121 8 Защита от взлома: сокеты, эксплойты и shell#код Ôóíêöèè ìàíèïóëèðîâàíèÿ ïàêåòàìè.....................................................121 Ôóíêöèè ìàíèïóëèðîâàíèÿ ñòðîêàìè.....................................................122 Êðèïòîãðàôè÷åñêèå ôóíêöèè.................................................................122 Èíòåðïðåòàòîð êîìàíä NASL ..................................................................122 Ïðèìåð.................................................................................................122 Ïðîãðàììèðîâàíèå â ñðåäå Nessus...............................................................124 Îïèñàòåëüíûå ôóíêöèè...........................................................................124 Ôóíêöèè, îòíîñÿùèåñÿ ê áàçå çíàíèé...............................................124 Ôóíêöèè èçâåùåíèÿ î ðåçóëüòàòàõ ðàáîòû.......................................125 Ïðèìåð.................................................................................................125 Ïðèìåð: êàíîíè÷åñêèé ñöåíàðèé íà ÿçûêå NASL.......................................127 Ïåðåíîñ íà ÿçûê NASL è íàîáîðîò...............................................................131 Ëîãè÷åñêèé àíàëèç .........................................................................................131 Ëîãè÷åñêàÿ ñòðóêòóðà ïðîãðàììû............................................................131 Ïñåâäîêîä .................................................................................................132 Ïåðåíîñ íà NASL ......................................................................................133 Ïåðåíîñ íà NASL ñ C/C++........................................................................134 Ïåðåíîñ ñ ÿçûêà NASL..............................................................................140 Ðåçþìå ................................................................................................................142 Îáçîð èçëîæåííîãî ìàòåðèàëà .....................................................................143 Ññûëêè íà ñàéòû................................................................................................144 ×àñòî çàäàâàåìûå âîïðîñû............................................................................145 Глава 3. BSD#сокеты............................................................................... 147 Ââåäåíèå .............................................................................................................148 Ââåäåíèå â ïðîãðàììèðîâàíèå BSD-ñîêåòîâ .............................................148 Êëèåíòû è ñåðâåðû äëÿ ïðîòîêîëà TCP........................................................149 Êîìïèëÿöèÿ ...................................................................................................151 Ïðèìåð âûïîëíåíèÿ......................................................................................151 Àíàëèç.............................................................................................................151 Êîìïèëÿöèÿ ...................................................................................................154 Ïðèìåð âûïîëíåíèÿ......................................................................................154 Àíàëèç.............................................................................................................154 Àíàëèç.............................................................................................................156 Êëèåíòû è ñåðâåðû äëÿ ïðîòîêîëà UDP.......................................................156 Êîìïèëÿöèÿ ...................................................................................................158 Ïðèìåð èñïîëíåíèÿ.......................................................................................158 Àíàëèç.............................................................................................................158 Содержание 9 Êîìïèëÿöèÿ ...................................................................................................160 Ïðèìåð èñïîëíåíèÿ.......................................................................................160 Àíàëèç.............................................................................................................161 Êîìïèëÿöèÿ ...................................................................................................163 Ïðèìåð èñïîëíåíèÿ.......................................................................................163 Àíàëèç.............................................................................................................163 Êîìïèëÿöèÿ ...................................................................................................165 Ïðèìåð èñïîëíåíèÿ.......................................................................................165 Àíàëèç.............................................................................................................165 Îïöèè ñîêåòîâ ..................................................................................................166 Àíàëèç.............................................................................................................168 Ñêàíèðîâàíèå ñåòè ñ ïîìîùüþ UDP-ñîêåòîâ............................................169 Êîìïèëÿöèÿ ...................................................................................................176 Ïðèìåð èñïîëíåíèÿ.......................................................................................176 Àíàëèç.............................................................................................................177 Ñêàíèðîâàíèå ñåòè ñ ïîìîùüþ TCP-ñîêåòîâ.............................................178 Êîìïèëÿöèÿ ...................................................................................................188 Ïðèìåð èñïîëíåíèÿ.......................................................................................188 Àíàëèç.............................................................................................................189 Ìíîãîïîòî÷íîñòü è ïàðàëëåëèçì..................................................................191 Ðåçþìå ................................................................................................................193 Îáçîð èçëîæåííîãî ìàòåðèàëà .....................................................................193 Ññûëêè íà ñàéòû................................................................................................195 ×àñòî çàäàâàåìûå âîïðîñû............................................................................195 Глава 4. Сокеты на платформе Windows (Winsock).........................197 Ââåäåíèå.............................................................................................................198 Îáçîð Winsock...................................................................................................198 Winsock 2.0.........................................................................................................200 Êîìïîíîâêà ñ èñïîëüçîâàíèåì Visual Studio 6.0...........................................201 Çàäàíèå êîìïîíîâêè â èñõîäíîì êîäå.........................................................201 Àíàëèç.............................................................................................................203 Ïðèìåð: ñêà÷èâàíèå Web-ñòðàíèöû ñ ïîìîùüþ WinSock......................206 Àíàëèç.............................................................................................................207 Ïðîãðàììèðîâàíèå êëèåíòñêèõ ïðèëîæåíèé............................................207 Àíàëèç.............................................................................................................210 Ïðîãðàììèðîâàíèå ñåðâåðíûõ ïðèëîæåíèé..............................................211 10 Защита от взлома: сокеты, эксплойты и shell#код Àíàëèç.............................................................................................................214 Íàïèñàíèå ýêñïëîéòîâ è ïðîãðàìì äëÿ ïðîâåðêè íàëè÷èÿ óÿçâèìîñòåé.......................................................................................................215 Àíàëèç.............................................................................................................222 Àíàëèç.............................................................................................................223 Ðåçþìå ................................................................................................................224 Îáçîð èçëîæåííîãî ìàòåðèàëà .....................................................................224 Ññûëêè íà ñàéòû................................................................................................225 ×àñòî çàäàâàåìûå âîïðîñû............................................................................226 Глава 5. Сокеты в языке Java ............................................................... 233 Ââåäåíèå .............................................................................................................234 Îáçîð ïðîòîêîëîâ TCP/IP...............................................................................234 TCP-êëèåíòû..................................................................................................235 Êîìïèëÿöèÿ..............................................................................................237 Ïðèìåð âûïîëíåíèÿ.................................................................................238 Àíàëèç.......................................................................................................238 Ðàçðåøåíèå IP-àäðåñîâ è äîìåííûõ èìåí....................................................239 Ïðèìåð âûïîëíåíèÿ.................................................................................240 Àíàëèç.......................................................................................................240 Ïðèìåð âûïîëíåíèÿ.................................................................................241 Àíàëèç.......................................................................................................242 Ââîä/âûâîä òåêñòà: êëàññ LineNumberReader.................................................242 Êîìïèëÿöèÿ..............................................................................................245 Ïðèìåð âûïîëíåíèÿ.................................................................................245 Àíàëèç.......................................................................................................245 TCP-ñåðâåðû...................................................................................................246 Êîìïèëÿöèÿ..............................................................................................249 Ïðèìåð âûïîëíåíèÿ.................................................................................249 Àíàëèç.......................................................................................................249 Èñïîëüçîâàíèå Web-áðàóçåðà äëÿ ñîåäèíåíèÿ ñ ñåðâåðîì TCPServer1 .......250 Ðàáîòà ñ íåñêîëüêèìè ñîåäèíåíèÿìè............................................................251 Êîìïèëÿöèÿ..............................................................................................257 Ïðèìåð âûïîëíåíèÿ.................................................................................257 Àíàëèç.......................................................................................................258 Ïðîãðàììà WormCatcher................................................................................260 Êîìïèëÿöèÿ..............................................................................................264 Ïðèìåð âûïîëíåíèÿ.................................................................................264 Àíàëèç.......................................................................................................265

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.