Как получить удаленный / одноранговый IP-адрес из структуры SSL / ssl_st в C? - PullRequest
1 голос
/ 28 мая 2020

То, что я пробовал ранее, - это получение fd сокета из SSL_get_wfd, а затем передача его getpeername. Я также посмотрел объект / функции BIO, но безуспешно. Пытался взглянуть на реализацию openSSL в /usr/include/openssl, но снова безуспешно.

Кто-нибудь знает, как получить удаленный IP-адрес (и порт), к которому подключен сокет openSSL?

Некоторый контекст:

socket fd: 64 // the file descriptor doesn't look incorrect (to me)
after getaddress, socklen: 28 // the length of the plausible address also looks correct
sockaddr ptr: 0x7b0b0fcac0, val: 0x0 // the pointer is empty despite being allocated :(

изменить: документация, на которой я основывал свою работу: https://docs.huihoo.com/doxygen/openssl/1.0.1c/structssl__st.html

1 Ответ

0 голосов
/ 30 мая 2020

Фрида имеет приятные функции, связанные с Socket s.

        var address = Socket.peerAddress(fd);
        // Assert address not null
        console.log(fd, address.ip + ':' + address.port);

Просмотр активности сокетов;

Process
  .getModuleByName({ linux: 'libc.so', darwin: 'libSystem.B.dylib', windows: 'ws2_32.dll' }[Process.platform])
  .enumerateExports().filter(ex => ex.type === 'function' && ['connect', 'recv', 'send', 'read', 'write'].some(prefix => ex.name.indexOf(prefix) === 0))
  .forEach(ex => {
    Interceptor.attach(ex.address, {
      onEnter: function (args) {
        var fd = args[0].toInt32();
        if (Socket.type(fd) !== 'tcp')
          return;
        var address = Socket.peerAddress(fd);
        if (address === null)
          return;
        console.log(fd, ex.name, address.ip + ':' + address.port);
      }
    })
  })

Пример вывода

$ frida -Uf com.example.app -l script.js --no-pause
[Android Model-X::com.example.app]-> 
117 write 5.0.2.1:5242
117 read 5.0.2.1:5242
135 write 5.0.2.1:4244
135 read 5.0.2.1:4244
135 read 5.0.2.1:4244
...