Weiter | Weiter | Weiter | Weiter | Kommentar

all-inOne, section 4.

4.  Intruders

The issue 1: https://buildsecurityin.us-cert.gov/swa/presentations_032011/CharlesHenderson-2011GlobalSecurityStatsAndTrends.pdf

The issue 2: http://www.cert.org/research/2010research-report.pdf

Page 111

CERT" The goal is to execute code, which was not intended to execute?

--
Before a break in
--
After a break in

4.1.  After a Break in

--
User files
--
System files
--
s-bit
--
libs
--
start up files
--
Configuration files
--
Comparison to an un-compromised system?

4.2.  Solution - Maybe Not

--
system files
--
system libraries
--
system configuration files

4.3.  Example

From: (Mon Jan 15 10:33:29 EST 2007) Hr -url http://en.wikipedia.org/wiki/X_Window_System http://en.wikipedia.org/wiki/X_Window_System

--
Color
--
Font
--
Icons
--
Functionality
,Ip editres - resource tree structure

4.4.  Xt - Motif - Athena - et all

From X11 man Page

4.5.  Examples

--
C source code:
 1      #include <X11/Intrinsic.h>
 2      #include <X11/StringDefs.h>     
 3      #include <X11/Xaw/Command.h>
 4      #include <X11/Xaw/Form.h>
 5      
 6      void main(int argc, char ** argv) {     Widget topLevel, button, knopf;
 7                                              /* Klassenname: Ex_1            */
 8              topLevel = XtInitialize(argv[0], "Ex_1", NULL, 0,
 9                                     &argc, argv);
10              button       = XtCreateManagedWidget("button", formWidgetClass, 
11                                                   topLevel, NULL,    0);
12              knopf       = XtCreateManagedWidget("this is the button",
13                                                   commandWidgetClass,        
14                                                   button, NULL,      0);
15              XtRealizeWidget(topLevel);
16                                              /*  Loop for events.            */
17              XtMainLoop();
18      }

Source Code: Src/7/ex_1.c

--
Resource file
 1      !
 2      ! Resource file for ex_1
 3      ! 
 4      #ifdef Class
 5              Ex_1.title:  class: ex_1
 6      #else
 7              Ex_1.title:  program: ex_1
 8      #endif
 9      Ex_1.width:  300
10      Ex_1.height: 300
11      Ex_1.box.this is the button.bitmap: mensetmanus
12      Ex_1.box.this is the button.label:  Press Me
13      Ex_1.box.this is the button.x:      10
14      Ex_1.box.this is the button.y:      10
15      Ex_1.box.this is the button.width:  100
16      Ex_1.box.this is the button.height: 50

Source Code: Src/7/Ex_1.rdb

--
Use:
% ex_1
% xrdb -load Ex_1.rdb
% ex_1

--
Add xhost + to .bashrc or eq.
--
Was:
 1      XTerm*VT100*translations: #override \n\
 2       Shift <KeyPress> Prior:        scroll-back(1,halfpage) \n\
 3        Shift <KeyPress> Next:        scroll-forw(1,halfpage) \n\
 4      Shift <KeyPress> Select:        select-cursor-start() \n\
 5      Shift <KeyPress> Insert:        insert-selection(PRIMARY, CUT_BUFFER0) \n\
 6              ~Meta<KeyPress>:        insert-seven-bit() \n\
 7               Meta<KeyPress>:        insert-eight-bit() \n\
 8              Ctrl <Btn1Down>:        popup-menu(mainMenu) \n\
 9         Lock Ctrl <Btn1Down>:        popup-menu(mainMenu) \n\
10             ~Meta <Btn1Down>:        select-start() \n\
11           ~Meta <Btn1Motion>:        select-extend() \n\
12              Ctrl <Btn2Down>:        popup-menu(vtMenu) \n\
13         Lock Ctrl <Btn2Down>:        popup-menu(vtMenu) \n\
14       ~Ctrl ~Meta <Btn2Down>:        ignore() \n\
15         ~Ctrl ~Meta <Btn2Up>:        insert-selection(PRIMARY, CUT_BUFFER0) \n\
16              Ctrl <Btn3Down>:        popup-menu(fontMenu) \n\
17         Lock Ctrl <Btn3Down>:        popup-menu(fontMenu) \n\
18       ~Ctrl ~Meta <Btn3Down>:        start-extend() \n\
19           ~Meta <Btn3Motion>:        select-extend() \n\
20                      <BtnUp>:        select-end(PRIMARY, CUT_BUFFER0) \n\
21                    <BtnDown>:        bell(0)         

Source Code: Src/7/Xterm

--
Is:
 1      !
 2      ! Resource file for funny things
 3      ! 
 4      *title: nicht wundern
 5      *bitmap: tie_fighter

Source Code: Src/7/myXterm

4.6.  Before a Break in

4.7.  Input Paths

--
self-replicating computer program
--
does not need to attach itself to an existing program
--
reproduce
--
hide themselves inside other programs to be executed

4.8.  Virus

--
1. sector on a disk
--
until specific conditions are met
--
scripting languages for programs such as Word and Excel
--
is spread by infecting documents and spreadsheets
--
sleeper
--
remote access

4.9.  Hardware - Drivers

4.10.  Software

--
Most Files are having programs in them - evaluated
--
Can a PDF file open a file?
--
Can a ps file open a file?

4.11.  System Calls versus Library Calls

--
Dynamic linking
--
Static linking
--
System Call are parts of the OS
--
System calls can not be modified
--
Arguments to system calls can be modified

4.12.  System call

[picture]

A system call creates an interrupt.

Questions:

The syscall function inside the OS:

#include "../port/systab.h"

long
syscall(Ureg *aur)
{
    long ret;
    ulong sp;
    Ureg *ur;

    ur = aur;
    if(ur->psr & PSRPSUPER)
        panic("recursive system call");
    u->p->insyscall = 1;
    u->p->pc = ur->pc;

    ...
    splhi();

    u->scallnr = ur->r7;
    sp = ur->usp;

    ...

        if(sp<(USTKTOP-BY2PG) || sp>(USTKTOP-sizeof(Sargs)))
            validaddr(sp, sizeof(Sargs), 0);

        u->s = *((Sargs*)(sp+1*BY2WD));
        u->p->psstate = sysctab[u->scallnr];

        ret = (*systab[u->scallnr])(u->s.args);

    spllo();

    return ret;
}

4.13.  A System Call Picture

4.14.  Exploit: Morris Worm

4.15.  What did it do?

--
modifies argc/argv -> ps does not show password
--
Open's files and deletes them -> continue to exists
--
Connects to telnet port and terminates immedietly -> /usr/adm/messages leaves a trace (was attacked)
--
Connects to other hosts
--
If the system reboots, rm -rf /usr/tmp, /tmp;mkdir /usr/tmp, /tmp;

4.16.  Buffer Overflow

4.17.  Standard Problem Issue

One:

 1      #include <stdio.h>
 2      
 3      int main() {
 4         char buffer[2];
 5         scanf("%s", buffer);
 6         printf("buffer= -%s-\n", buffer);
 7      }

Source Code: Src/7_1/readIn_1.c

Two:

 1      #include <stdio.h>
 2      
 3      int main() {
 4         char buffer[2];
 5         int n;
 6         if ( (n = scanf("%s", buffer)) > sizeof(buffer) )
 7              printf("bad things may happen\n");
 8         printf("buffer= -%s-\n", buffer);
 9         printf("sizeof(buffer)= -%d-\n", sizeof(buffer));
10         printf("n= -%d-\n", n);
11      }

Source Code: Src/7_1/readIn_2.c Three:

 1      #include <stdio.h>
 2      
 3      int main() {
 4         char buffer[2];
 5         int index = 0;
 6      
 7         while ( index <= sizeof(buffer) ) {
 8                 printf("index= -%d-\n", index);
 9                 if ( index >= sizeof(buffer) )       {
10                      printf("something bad will happen");
11                      exit(1);
12                 }
13                 scanf("%c", &buffer[index++]);
14         }
15         printf("buffer= -%s-\n", buffer);
16      }

Source Code: Src/7_1/readIn_3.c

4.18.  Process Memory Organization

4.19.  Stack Frames

Stack

4.20.  Use of the Stack During Execution

4.21.  Buffer Overflows

The C code:

 1      void function(char *str) {
 2         char buffer[0];
 3      
 4         strcpy(buffer,str);
 5      }
 6      
 7      int main() {
 8        char large_string[256];
 9        int i;
10      
11        for( i = 0; i < 255; i++)
12          large_string[i] = 'A';
13      
14        function(large_string);
15      }

Source Code: Src/7_1/example2.c

4.22.  The Idea

4.23.  Execute Code -I

4.24.  Execute Code -II

--
placing the code which should be execcuted in the buffer which we will overflow
--
overwrite the return address so it points back into the buffer.

4.25.  Finding the Bits to execute

gdb shellcode
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.15 (i586-unknown-linux), Copyright 1995 Free Software Foundation, Inc...
(gdb) disassemble main
Dump of assembler code for function main:
0x8000130 <main>:       pushl  %ebp
0x8000131 <main+1>:     movl   %esp,%ebp
0x8000133 <main+3>:     subl   $0x8,%esp
0x8000136 <main+6>:     movl   $0x80027b8,0xfffffff8(%ebp)
0x800013d <main+13>:    movl   $0x0,0xfffffffc(%ebp)
0x8000144 <main+20>:    pushl  $0x0
0x8000146 <main+22>:    leal   0xfffffff8(%ebp),%eax
0x8000149 <main+25>:    pushl  %eax
0x800014a <main+26>:    movl   0xfffffff8(%ebp),%eax
0x800014d <main+29>:    pushl  %eax
0x800014e <main+30>:    call   0x80002bc <__execve>
0x8000153 <main+35>:    addl   $0xc,%esp
0x8000156 <main+38>:    movl   %ebp,%esp
0x8000158 <main+40>:    popl   %ebp
0x8000159 <main+41>:    ret
End of assembler dump.
(gdb) disassemble __execve
Dump of assembler code for function __execve:
0x80002bc <__execve>:   pushl  %ebp
0x80002bd <__execve+1>: movl   %esp,%ebp
0x80002bf <__execve+3>: pushl  %ebx
0x80002c0 <__execve+4>: movl   $0xb,%eax
0x80002c5 <__execve+9>: movl   0x8(%ebp),%ebx
0x80002c8 <__execve+12>:        movl   0xc(%ebp),%ecx
0x80002cb <__execve+15>:        movl   0x10(%ebp),%edx
0x80002ce <__execve+18>:        int    $0x80
0x80002d0 <__execve+20>:        movl   %eax,%edx
0x80002d2 <__execve+22>:        testl  %edx,%edx
0x80002d4 <__execve+24>:        jnl    0x80002e6 <__execve+42>
0x80002d6 <__execve+26>:        negl   %edx
0x80002d8 <__execve+28>:        pushl  %edx
0x80002d9 <__execve+29>:        call   0x8001a34 <__normal_errno_location>
0x80002de <__execve+34>:        popl   %edx
0x80002df <__execve+35>:        movl   %edx,(%eax)
0x80002e1 <__execve+37>:        movl   $0xffffffff,%eax
0x80002e6 <__execve+42>:        popl   %ebx
0x80002e7 <__execve+43>:        movl   %ebp,%esp
0x80002e9 <__execve+45>:        popl   %ebp
0x80002ea <__execve+46>:        ret
0x80002eb <__execve+47>:        nop
End of assembler dump.

4.26.  The Explanation

0x8000130 <main>:       pushl  %ebp
0x8000131 <main+1>:     movl   %esp,%ebp
0x8000133 <main+3>:     subl   $0x8,%esp

This is the procedure prelude. It first saves the old frame pointer, makes the current stack pointer the new frame pointer, and leaves space for the local variables. In this case its:

char *name[2];

or 2 pointers to a char. Pointers are a word long, so it leaves space for two words (8 bytes).

0x8000136 <main+6>:     movl   $0x80027b8,0xfffffff8(%ebp)

We copy the value 0x80027b8 (the address of the string "/bin/sh") into the first pointer of name[]. This is equivalent to:

name[0] = "/bin/sh";

0x800013d <main+13>:    movl   $0x0,0xfffffffc(%ebp)

We copy the value 0x0 (NULL) into the seconds pointer of name[]. This is equivalent to:

name[1] = NULL;

The actual call to execve() starts here.

0x8000144 <main+20>:    pushl  $0x0

We push the arguments to execve() in reverse order onto the stack. We start with NULL.

0x8000146 <main+22>:    leal   0xfffffff8(%ebp),%eax

We load the address of name[] into the EAX register.

0x8000149 <main+25>:    pushl  %eax

We push the address of name[] onto the stack.

0x800014a <main+26>:    movl   0xfffffff8(%ebp),%eax

We load the address of the string "/bin/sh" into the EAX register.

0x800014d <main+29>:    pushl  %eax

We push the address of the string "/bin/sh" onto the stack.

0x800014e <main+30>:    call   0x80002bc <__execve>

Call the library procedure execve(). The call instruction pushes the IP onto the stack.

Now execve(). Keep in mind we are using a Intel based Linux system. The syscall details will change from OS to OS, and from CPU to CPU. Some will pass the arguments on the stack, others on the registers. Some use a software interrupt to jump to kernel mode, others use a far call. Linux passes its arguments to the system call on the registers, and uses a software interrupt to jump into kernel mode.

0x80002bc <__execve>:   pushl  %ebp
0x80002bd <__execve+1>: movl   %esp,%ebp
0x80002bf <__execve+3>: pushl  %ebx

The procedure prelude.

0x80002c0 <__execve+4>: movl   $0xb,%eax

Copy 0xb (11 decimal) onto the stack. This is the index into the syscall table. 11 is execve.

0x80002c5 <__execve+9>: movl   0x8(%ebp),%ebx

Copy the address of "/bin/sh" into EBX.

0x80002c8 <__execve+12>:movl   0xc(%ebp),%ecx

Copy the address of name[] into ECX.

0x80002cb <__execve+15>:movl   0x10(%ebp),%edx

Copy the address of the null pointer into %edx.

0x80002ce <__execve+18>:int    $0x80

Change into kernel mode.

4.27.  Overview

4.28.  Excec may Be Unsucessful

 1      #include <stdlib.h>
 2      
 3      int main() {
 4              exit(0);
 5      }

Source Code: Src/7_1/exit.c

[aleph1]$ gcc -o exit -static exit.c
[aleph1]$ gdb exit
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.15 (i586-unknown-linux), Copyright 1995 Free Software Foundation, Inc...
(no debugging symbols found)...
(gdb) disassemble _exit
Dump of assembler code for function _exit:
0x800034c <_exit>:      pushl  %ebp
0x800034d <_exit+1>:    movl   %esp,%ebp
0x800034f <_exit+3>:    pushl  %ebx
0x8000350 <_exit+4>:    movl   $0x1,%eax
0x8000355 <_exit+9>:    movl   0x8(%ebp),%ebx
0x8000358 <_exit+12>:   int    $0x80
0x800035a <_exit+14>:   movl   0xfffffffc(%ebp),%ebx
0x800035d <_exit+17>:   movl   %ebp,%esp
0x800035f <_exit+19>:   popl   %ebp
0x8000360 <_exit+20>:   ret
0x8000361 <_exit+21>:   nop
0x8000362 <_exit+22>:   nop
0x8000363 <_exit+23>:   nop
End of assembler dump.

4.29.  In Short

4.30.  The End

4.31.  Monitoring

See Leon Reznik's research area

4.32.  Conclusion

--
Take CS as an example
--
Take RIT as an example
--
Take president Simone as an example

Weiter | Weiter | Weiter | Weiter | Kommentar


Created by unroff, java2html & & hp-tools. © by hpb. All Rights Reserved (2012).
It is not allowed to print these pages on a CAST printer.
Last modified 22/February/12