版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、1計算機網(wǎng)絡攻擊和防護技術第二課2HackingUsing ways most people are not aware of用1, 3,4, 6 和任意+,-,*,/, 寫一個等式, 結果為24. Against common thought and what designers intendExample3簡單程序/hacking/booksrc cat firstprog.c #include int main() int i; for(i=0; i gcc firstprog.c /hacking/booksrc ls -l a.out-rwxr-x- 1 wushaow nscn 3
2、6588 Sep 16 18:02 a.out*/hacking/booksrc ./a.outHello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!5簡單程序/hacking/booksrc objdump -D a.out000108c0 : 108c0: 9d e3 bf 88 save %sp, -120, %sp 108c4: 01 00 00 00 nop 108c8: c0 27 bf ec cl
3、r %fp + -20 108cc: d0 07 bf ec ld %fp + -20 , %o0 108d0: 80 a2 20 09 cmp %o0, 9 108d4: 04 80 00 04 ble 108e4 108d8: 01 00 00 00 nop 108dc: 10 80 00 0b b 10908 108e0: 01 00 00 00 nop 108e4: 13 00 00 46 sethi %hi(0 x11800), %o1 108e8: 90 12 62 30 or %o1, 0 x230, %o0 ! 11a30 108ec: 40 00 44 a1 call 21b
4、70 108f0: 01 00 00 00 nop 108f4: d0 07 bf ec ld %fp + -20 , %o0 108f8: 92 02 20 01 add %o0, 1, %o1 108fc: d2 27 bf ec st %o1, %fp + -20 10900: 10 bf ff f3 b 108cc 10904: 01 00 00 00 nop 10908: 81 c7 e0 08 ret 1090c: 81 e8 00 00 restore 6簡單程序Assembly language output will be different on different typ
5、e of computer, compilerObjdump will have more output than shown here7DebuggerDebugger are used by programmers to step through compiled programExamine program memoryView Process registersFind out source of coreGNU development tools include a debugger-GDBA debugger allows a hacker to observe the micro
6、scopic world of machine code8GDB exampleUsing GDB to show the information of a programExample: Intel ArchitectureGeneral Registers: EAX: EBX: ECX: EDX: Pointers and Index RegistersESP: Stack PointerEBP: Base pointerESI: Source IndexEDI: Destination indexEIP: Instruction pointerEFLAGS: several bits f
7、lags that are used for comparisions and memory segmentspg_17.pdf9Assembly LanguageList the source codeDisassembly the source codeassembly_main.pdf10Assembly Languagei r eipInfo register eipCommand x: examineExamining memoryExample: (gdb) x/8xwx_command.pdfEndian11Assembly LanguageCommand x: examineE
8、xamining memory instruction x/iExample: (gdb) x/8ix_command_i.pdf12Memory SegmentsA compiled program is divided into five segmentsText: code segmentNot writableData: initialized global and static variablesWritable, fixed sizeBSS: uninitlized global and static variablesWritable, fixed sizeHeap: memor
9、y that can be controlled by program directlyVariable sizeStack: temporary scratch pad to store local variablesVariable sizeStack framememory_segment.pdf13Memory Segments in CText: compiled code go into text segmentNot writableData: initialized global and static variablesWhat is static keyword?Static
10、 variable in a file will be in local file scopeStatic in a function will be a static value inside the functionGlobal variables defined in file scope without any static declaration) is a global variableDefault is globalWritable, fixed sizeBSS: uninitialized global and static variablesWritable, fixed
11、sizeHeap: memory that can be controlled by program directlyVariable sizeMemory on heap memory must first allocated by using malloc()Used pointer to refer to memory allocatedMemory on heap memory must be freed after use using free()Dynamic memory allocationStack: temporary scratch pad to store local
12、variablesVariable sizeFunction variables are stored in the stack memoryStack framememory_segment_c.pdf14Stack FrameLocal data 2Local data 1Save frame pointer(SFP)Return address (ret)Caller framelow addressTop of Stackhigh addressFrame Pointer (EBP)Stack Growth15Using HeapHeap: memory that can be con
13、trolled by program directlyVariable sizeMemory on heap memory must first allocated by using malloc()Used pointer to refer to memory allocatedNeed to check the return pointer, if null, need to handle errorReturn value is a null pointerMemory on heap memory must be freed after use, using free()Dynamic
14、 memory allocationusing_heap.pdf16User IDsEvery User on a Unix/Linux system has a unique user ID numberUsing id command/hacking/booksrc id wushaowuid=8249(wushaow) gid=893(nscn)/hacking/booksrc id rootuid=0(root) gid=1(other)root user (with id 0) is like the administrator accountsu command can be us
15、ed to switch to different usersudo command allows a single command to be run as the root userSetuser id (setuid) Additional file permission bit that can be set using chmodRunning program has both a real user id and an effective user IDgetuid(): get real user idgeteuid() get effective user id One of
16、the goal of hacking is to get the right of root.17Process Operations and IDsRootID=0 for superuser root; can access any fileFork and ExecInherit three IDs, except exec of file with setuid bitSetuid system calls seteuid(newid) can set EUID toReal ID or saved ID, regardless of current EUIDAny ID, if E
17、UID=0Details are actually more complicatedSeveral different calls: setuid, seteuid, setreuid18Setid bits on executable Unix fileThree setid bitsSetuid set EUID of process to ID of file ownerSetgid set EGID of process to GID of fileStickyOff: if user has write permission on directory, can rename or r
18、emove files, even if not ownerOn: only file owner, directory owner, and root can rename or remove file in the directory19Example;exec( );RUID 25SetUIDprogram;i=getruid()setuid(i);RUID 25EUID 18RUID 25EUID 25-rw-r-r-file-rw-r-r-fileOwner 18Owner 25read/writeread/writeOwner 1820Compare to stack inspec
19、tionCareful with Setuid !Can do anything that owner of file is allowed to doBe sure not toTake action for untrusted userReturn secret data to untrusted userA1B1C1Note: anything possible if root; no middle ground between user and root21Setuid programmingBe Careful!Root can do anything; don t get tric
20、kedPrinciple of least privilege change EUID when root privileges no longer neededSetuid scriptsThis is a bad ideaHistorically, race conditionsBegin executing setuid program; change contents of program before it loads and is executed22Unix summaryGood thingsSome protection from most usersFlexible eno
21、ugh to make things possibleMain bad thingToo tempting to use root privilegesNo way to assume some root privileges without all root privileges23計算機網(wǎng)絡攻擊和防護技術第三課24Overview of the 80 x86 Family Assembly LanguageNumbers1 BIT: 0 1 NIBBLE: 0000 4 BITS 1 BYTE 00000000 2 NIBBLES, 8 BITS HALF WORD 00000000000
22、00000 2 BYTES, 4 NIBBLES, 16 BITS1 WORD 0000000000000000 0000000000000000 4 bytes, 32 bits25Intel Registers General purpose registersEAX: Accumulator RegisterEBX: Base register ECX: Counter registerEDX: Data registerIndex registerspointer registers and they are 32-bit registers. mainly used for stri
23、ng instructionsEDI: destination index ESI: source index EIP: instruction pointer, point to the current instruction the process is readingStack registersEBP and ESP are stack registers and are used when dealing with the stackESP: stack pointerEBP: stack base pointerEFLAGSSeveral bits flag that are us
24、ed for comparisons and memory segmentsCan be ignored most time since no direct access needed. Segment registersEDS stores the Segment and ESI stores the offset 26Stack Review27Assembly Instructions Move instructionsmov eax,10 ; /*put 10 into eax */mov ebx,20 ; /*put 20 into ebx */mov ecx,30 ; /*put
25、30 into ecx */mov edx,40 ; /*put 40 into edx */in assembler anything after a ; (semicolon) is ignored. very useful for commenting your code. 28Assembly Instructions Move instructionsmov eax,10 ; /*put 10 into eax */mov ebx,20 ; /*put 20 into ebx */mov ecx,30 ; /*put 30 into ecx */mov edx,40 ; /*put
26、40 into edx */Notice that in assembler anything after a ; (semicolon) is ignored. This is very useful for commenting your code. 29Assembly Instructions Push and Pop: Two Instructions to use the StackPUSH: Puts a piece of data onto the top of the stack Syntax: push dataPOP: Puts the piece of data fro
27、m the top of the stack into a specified register or variable. Syntax: pop register (or variable) Example;push ecx ; /*put ecx on the stack */push eax ; /*put eax on the stack */pop ecx ; /*put value from stack into ecx */pop eax ; /*put value from stack into eax */ 30Types of OperandImmediatenumber
28、which will be known at compilation and will always be the sameexample 20 or A.Registerany general purpose or index register example EAX or ESIMemorya variable which is stored in memory 31InstructionsMOV: moves a value from one place to another.MOV destination, sourcemov ax,10 ; /*moves an immediate
29、value into eax*/.mov ebx,ecx ; /*moves value from cx into ebx */mov edx, 10 ; /*moves the value of Number into edx*/ INT: calls a Interrupt processing subroutingINT interrupt numberint 21h ; /*Calls DOS service*/ int 10h ; /*Calls the Video BIOS interrupt*/32Control Flowjmp label jmp ALabel . . . AL
30、abel:JA Jumps if the first number was above the second numberJAE same as above, but will also jump if they are equalJB jumps if the first number was below the secondJBE Same as above, but will also jump if they are equalJNA jumps if the first number was NOT above (JBE)JNAE jumps if TDe first number
31、was NOT above or TDe same as (JNB)JNB jumps if the first number was NOT below (JAE) JNBE jumps if the first number was NOT below or the same as (JA)JZ jumps if the two numbers were equalJE same as JZ, just a different nameJNZ jumps if the two numbers are NOT equalJNE same as aboveJC jump if carry fl
32、ag is set CMP: compare a value Syntax: CMP register or variable, value jxx destination 33Important instructionsADD operand1,operand2 adds operand2 to operand1. The answer is stored in operand1Immediate data cannot be used as operand1 but can be used as operand2. SUB operand1,operand2 subtracts opera
33、nd2 from operand1. Immediate data cannot be used as operand1 but can be used as operand2xorIncdecMUL: Multiplies two unsigned integers (always positive)IMUL: Multiplies two signed integers (either positive or negitive) DIV: Divides two unsigned integers (always positive) IDIV: Divides two signed int
34、egers (either positive or negitive) 34ExploitationProgram is designed by people to follow the predefined flowExploitation is used the clever way to let the program do what you want to do, not what the designer/ proggramer want itLaMacChia LoopholeUS leagal system loophole1993 MIT student David LaMac
35、chia (Hacker)35ExploitationMost program exploits has to do with Memory corruptionTake control of running programs flow and hijack it to run the marlious codeExecution of arbitrary codeExample:Buffer overflowHeap overflowFormat string exploitsInteger overflow36Buffer OverflowsC is unsafe languageOnce
36、 memory is allocated, no safe-guard to ensure data to be stored in the allocated memory only.buffer_overflow.pdfstrcpy(searchingstring, argv1);37Using scrip to make attack easierBASH SHELLPerlCommon to most Unix based machineTell Perl to execute the commands found beteen single quotes/hacking/booksr
37、c perl -e print A x20;AAAAAAAAAAAAAAAAAAAAAny character, can use x# hexadecimal value of the characterCan apply to non-printable character too. A = 0 x41, so can use x41/hacking/booksrc perl -e print x41 x20; AAAAAAAAAAAAAAAAAAAA38Perl String concatString concatenation can be done in Perl with a per
38、iod /hacking/booksrcperl -e print A x20 . BCD . x61x66x67x69 x2 . Z AAAAAAAAAAAAAAAAAAAABCDafgiafgiZShell command can be executed like a function, using $() formatperl_example.pdfCommand substitution and Perl can be used in combination to quickly generate overflow buffer in fly.39ShellcodeShellcodeO
39、verflow a buffer into the return addressInject own instructions intommemory and then return the execution thereOriginal meaning: spawn a shell (rootshell) used to control the machineExtends to spawn a method that can be used to control the machineOpen connect back portshellcode_example.pdfWhen a new instruction can be injected in and execution can be controlled with a buffer overflow, the original design is voidAllow programs to do things i
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度家政服務業(yè)與洗衣店深度合作合同2篇
- 二零二五年度房屋租賃裝修保證金合同范本3篇
- 二零二五年度海洋工程設備安裝與維護合同6篇
- 二零二五年度水上交通安全評價與船舶安全檢驗合同3篇
- 二零二五年度房產(chǎn)抵押個人養(yǎng)老貸款合同3篇
- 二零二五年度國畫收藏品鑒定與買賣合同3篇
- 環(huán)形運動器材及課程設計
- 海南職業(yè)技術學院《對外漢語教育學引論》2023-2024學年第一學期期末試卷
- 二零二五年度區(qū)塊鏈技術應用合同條款與數(shù)字資產(chǎn)交易規(guī)則3篇
- 2025版建筑工程安全防護股份制合作協(xié)議書3篇
- 2023-2024學年甘肅省嘉峪關市酒鋼三中高三上數(shù)學期末學業(yè)質(zhì)量監(jiān)測試題含解析
- 水利機械施工方案
- 懸挑式腳手架驗收記錄表
- 主變壓器試驗報告模板
- 電動叉車安全操作規(guī)程
- 靜鉆根植樁施工組織設計
- 工程精細化管理
- 柴油供貨運輸服務方案
- 2022年長春市中小學教師筆試試題
- 肉牛肉羊屠宰加工項目選址方案
- 清洗劑msds清洗劑MSDS
評論
0/150
提交評論