netcat如何通过套接字运行脚本或二进制文件?用C怎么做?

问题描述

在传统的nc程序包中,我们可以使用-e标签来指定一个环境,例如/bin/bash,它将在nc侦听器中打开bash。我们还可以提供脚本或其他内容,它始终可以交互工作。我的问题是,它是如何工作的?又例如如何用C语言编程呢?使用popen吗?我已经看过nc源代码,但是很长一段时间我都没有看到想要看到的内容。抱歉,是否已经在其他地方询问过这个问题? 编辑:我找到了一个功能,但我不能完全理解它。这是启用-e标签时激活的功能

static void ncexec(nc_sock_t *ncsock)
{
  int saved_stderr;
  char *p;
  assert(ncsock && (ncsock->fd >= 0));

  /* save the stderr fd because we may need it later */
  saved_stderr = dup(STDERR_FILENO);

  /* duplicate the socket for the child program */
  dup2(ncsock->fd,STDIN_FILENO);   /* the precise order of fiddlage */
  close(ncsock->fd);            /* is apparently crucial; this is */
  dup2(STDIN_FILENO,STDOUT_FILENO);    /* swiped directly out of "inetd". */
  dup2(STDIN_FILENO,STDERR_FILENO);    /* also duplicate the stderr channel */

  /* change the label for the executed program */
  if ((p = strrchr(opt_exec,'/')))
    p++;            /* shorter argv[0] */
  else
    p = opt_exec;

  /* replace this process with the new one */
#ifndef USE_OLD_COMPAT
  execl("/bin/sh",p,"-c",opt_exec,NULL);
#else
  execl(opt_exec,NULL);
#endif
  dup2(saved_stderr,STDERR_FILENO);
  ncprint(NCPRINT_ERROR | NCPRINT_EXIT,_("Couldn't execute %s: %s"),strerror(errno));
}               /* end of ncexec() */

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...