fix dns leak for .onion, update via, resolve hostname

This commit is contained in:
creeper123123321 2021-04-21 17:00:46 -03:00
parent 5d042477e6
commit df60190dc3
5 changed files with 21 additions and 16 deletions

View File

@ -108,3 +108,4 @@ How to connect to 1.7.10 and lower servers with a newer client?
Can I use it to connect to .onion Minecraft hidden servers?
- You can use .onion addresses if the instance is proxying the backend connections to TOR.
Note that VIAaaS may log your requests.

View File

@ -47,7 +47,7 @@ repositories {
}
dependencies {
implementation("us.myles:viaversion:3.3.0-21w15a") { isTransitive = false }
implementation("us.myles:viaversion:3.3.0-21w16a") { isTransitive = false }
implementation("nl.matsv:viabackwards:3.3.0-21w15a") { isTransitive = false }
implementation("com.github.ViaVersion.ViaRewind:viarewind-all:dev-SNAPSHOT") { isTransitive = false }
implementation("io.netty:netty-all:4.1.63.Final")

View File

@ -37,6 +37,7 @@ val viaaasLogger = LoggerFactory.getLogger("VIAaaS")
val secureRandom = if (VIAaaSConfig.useStrongRandom) SecureRandom.getInstanceStrong() else SecureRandom()
fun resolveSrv(hostAndPort: HostAndPort): HostAndPort {
if (hostAndPort.host.endsWith(".onion", ignoreCase = true)) return hostAndPort
if (hostAndPort.port == 25565) {
try {
// https://github.com/GeyserMC/Geyser/blob/99e72f35b308542cf0dbfb5b58816503c3d6a129/connector/src/main/java/org/geysermc/connector/GeyserConnector.java

View File

@ -98,16 +98,16 @@ fun connectBack(handler: MinecraftHandler, address: String, port: Int, state: St
val removedEndDot = srvResolved.host.replace(Regex("\\.$"), "")
val iterator =
if (!removedEndDot.endsWith(".onion")) {
InetAddress.getAllByName(srvResolved.host)
.groupBy { it is Inet4Address }
.toSortedMap() // I'm sorry, IPv4, but my true love is IPv6... We can still be friends though...
.map { InetSocketAddress(it.value.random(), srvResolved.port) }
val iterator = when {
removedEndDot.endsWith(".onion", ignoreCase = true) ->
listOf(InetSocketAddress.createUnresolved(removedEndDot, srvResolved.port))
.iterator()
} else {
listOf(InetSocketAddress.createUnresolved(removedEndDot, srvResolved.port)).iterator()
}
else -> InetAddress.getAllByName(srvResolved.host)
.groupBy { it is Inet4Address }
.toSortedMap() // I'm sorry, IPv4, but my true love is IPv6... We can still be friends though...
.map { InetSocketAddress(it.value.random(), srvResolved.port) }
.iterator()
}
if (!iterator.hasNext()) throw StacklessException("Hostname has no IP address")
tryBackAddress(handler, iterator, state, success)

View File

@ -88,12 +88,15 @@ class WebDashboardServer {
if (!listeners.containsKey(id)) {
future.completeExceptionally(StacklessException("No browser listening"))
} else {
val info = try {
if (address is InetSocketAddress) {
ipInfo.lookupIP(address.address.hostAddress.substringBefore("%"))
} else null
} catch (ignored: Exception) {
null
val info = withContext(Dispatchers.IO) {
(address as? InetSocketAddress).let {
try {
it?.address?.hostName // resolve it
ipInfo.lookupIP(it?.address?.hostAddress?.substringBefore("%"))
} catch (ignored: Exception) {
null
}
}
}
val msg =
"Client: $address (${info?.org}, ${info?.city}, ${info?.region}, ${info?.countryCode})\nBackend: $backAddress"