socketry / db-mariadb

MIT License
10 stars 1 forks source link

Automatically resolve hostnames when connecting to a server #4

Open postmodern opened 3 months ago

postmodern commented 3 months ago

libmariadb (and libmysql-client) still for some reason insists on only accepting IP addresses for the host: keyword argument. It would be useful to automatically resolve hostnames to IPs for the user. This would match the behavior of db-postgres.

ioquatix commented 3 months ago

That makes sense.

ioquatix commented 3 months ago

It's okay I'll sort it out. These gems need a bit of TLC.

postmodern commented 3 months ago

For recognizing IP addresses you could use IPAddr::RE_IPV4ADDRLIKE and IPAddr::RE_IPV6ADDRLIKE_COMPRESSED, or Resolv::IPv4::Regex and Resolv::IPv6::Regex.

ioquatix commented 3 months ago

Do you mind elaborating on the root problem? Are you seeing an error when you give a hostname?

postmodern commented 3 months ago

Do you mind elaborating on the root problem? Are you seeing an error when you give a hostname?

It makes it awkward to use db-postgres vs. db-mariadb via a CLI util, where one raises an odd exception when db-mariadb is given a hostname but db-postgres does not. Currently, I had to add a method to explicitly resolve the hostname for the mysql bruteforcer as a workaround.

$ ./bin/ronin-brute run mysql -p host=localhost -p database=db --usernames usernames.txt --passwords passwords.txt 
>>> Bruteforcing localhost:3306 ...
  0.0s     warn: Async::Task [oid=0xeb0] [ec=0xec4] [pid=4761] [2024-07-26 10:44:37 -0700]
               | Task may have ended with unhandled exception.
               |   Errno::EBADF: Bad file descriptor
               |   → /data/home/postmodern/code/ronin-rb/vendor/bundle/ruby/3.1.0/gems/db-mariadb-0.10.0/lib/db/mariadb/native/connection.rb:71 in `initialize'
$ ./bin/ronin-brute run postgres -p host=localhost -p database=db --usernames usernames.txt --passwords passwords.txt 
>>> Bruteforcing localhost:5432 ...
>>> Found credentials admin:password1234