标签: execve

C - 通过 execve 传递管道

我正在为学校做一个项目,我不确定我试图解决它的方式是否可行。该项目涉及制作一个程序,分叉出 2 个孩子,然后必须用其他程序替换他们的 pid,并让 2 个孩子通过使用 read() 和 write() 通过管道交谈。

我的问题是使用 execve 并将管道传递给那个孩子。我现在所拥有的是:

父程序 - 分叉并让孩子调用 execve:

#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>

#define BUF_SIZE 16

/*  2 cmd line arguments
    1. file already in system (to be copied)
    2. file to be created (the copy)
create pipe (for communication) + 2 child processes
    first child replace pid with reader
    second child with writer
    wait for both children to terminate before exiting
*/

int …
Run Code Online (Sandbox Code Playgroud)

c pipe exec execve

1
推荐指数
1
解决办法
1万
查看次数

在Shellcode中堆栈内存地址

我正在阅读一篇关于编写shellcode(使用堆栈方法的execve)的基本文章:http://hackoftheday.securitytube.net/2013/04/demystifying-execve-shellcode-stack.html

在步骤6中:它推送空字符,因为字符串"/ bin/sh"为空终止.之后,它以相反的顺序推送字符串"/ bin/sh"

为什么字符串以相反的顺序被推入堆栈?为什么在将字符串推入堆栈之前"推出"字符串的空字符?

stack execve shellcode

0
推荐指数
1
解决办法
1332
查看次数

execve 到我刚刚写的文件——“文本文件忙”

下面的 C 程序的预期行为是将其自己的可执行文件复制到一个新的随机命名的文件,然后执行该文件,令人作呕。这应该创建很多很多可执行文件的副本。这显然是一个糟糕的想法,但这仍然是我正在尝试做的事情。

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>

int main(int argc, char* argv[]) {

  /* Obtain name of current executable */
  const char* binName = argv[0];

  /* Print message */
  printf("Hello from %s!\n", binName);

  /* Create name of new executable */
  char newBinName[] = "tmpXXXXXX";
  mkstemp(newBinName);

  /* Determine size of current executable */
  struct stat st;
  stat(binName, &st);
  const int binSize = st.st_size;

  /* Copy current executable to memory */
  char* binData = (char*) malloc(sizeof(char) * binSize); …
Run Code Online (Sandbox Code Playgroud)

c linux execve

0
推荐指数
1
解决办法
1605
查看次数

程序集执行 /bin/bash (x64)

我是 asm 的新手,我正在尝试对 /bin/bash 执行系统调用。但是我目前遇到以下问题:

我的代码适用于第一个参数长度小于 8 个字节的任何 execve 调用,即 "/bin/sh" 或 "/bin/ls" :

.section .data

    name: .string "/bin/sh"

.section .text

.globl _start

_start:
    #third argument of execve, set to NULL
    xor %rdx, %rdx 

    #push nullbyte to the stack
    pushq %rdx 

    #push /bin/sh to the stack
    pushq name 

    #copy stack to rdi, 1st arg of execve
    mov %rsp, %rdi 

    #copy 59 to rax, defining syscall number for execve  
    movq $59, %rax 

    #3rd arg of execve set to NULL
    movq $0, …
Run Code Online (Sandbox Code Playgroud)

64-bit assembly system-calls execve

0
推荐指数
1
解决办法
4490
查看次数

XOR如何防止shellcode中的NULL字节

我一直在尝试按照本教程(https://paraschetal.in/writing-your-own-shellcode)来编写自己的shellcode.其中99%对我有意义,但我心中只有两个疑惑 - 这与编写shellcode有关

首先,我想我明白为什么我们要避免空字节但是如何使用以下避免空字节?

xor eax, eax
Run Code Online (Sandbox Code Playgroud)

eax现在不包含完全空字节?或者它包含0?当我们对自己进行异或时,它会返回False,对吗?

其次,教程说:

最后,我们将把系统调用号(11或0xb)加载到eax寄存器.但是,如果我们在指令中使用eax,生成的shellcode将包含一些NULL(\ x00)字节,我们不希望这样.我们的eax寄存器已经是NULL.因此,我们只需将系统调用号加载到al寄存器而不是整个eax寄存器.

mov byte  al, 0x0b
Run Code Online (Sandbox Code Playgroud)

现在我明白了这里发生了什么,数字11(for execve)被加载到eax寄存器的前8位(即al).但其余的eax仍然包含空字节,那么究竟是什么在这里实现的?

请注意,在我花了大部分时间试图理解这一点后,我作为最后的手段来到这里,所以请放轻松我:)

c assembly execve shellcode

0
推荐指数
1
解决办法
332
查看次数

标签 统计

execve ×5

c ×3

assembly ×2

shellcode ×2

64-bit ×1

exec ×1

linux ×1

pipe ×1

stack ×1

system-calls ×1