forked from kimocoder/armitage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kimocoder#3 from Moocow9m/rewrite
Merge changes
- Loading branch information
Showing
9 changed files
with
167 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file was deleted.
Oops, something went wrong.
59 changes: 0 additions & 59 deletions
59
src/main/kotlin/com/wavProductions/www/armitage/Metasploit.kt
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.wavproductions.www.armitage | ||
|
||
import com.wavproductions.viken.Viken | ||
import com.wavproductions.viken.VikenImage | ||
import com.wavproductions.www.armitage.Config.loadConfig | ||
import java.io.InputStream | ||
import java.nio.file.Files | ||
import java.nio.file.Paths | ||
|
||
fun main(args: Array<String>) { | ||
val resources = Paths.get("resources").toAbsolutePath() | ||
if (Files.notExists(resources)) { | ||
Files.createDirectories(resources) | ||
} | ||
loadConfig() | ||
val conn = Metasploit() | ||
val debug = args.contains("debug-cmd") //testing metasploit connection and calls | ||
if (debug) { | ||
conn.load(debug = true) | ||
|
||
} else { | ||
val iconPath = Paths.get(resources.toString(), "icon.png") | ||
if (Files.notExists(iconPath)) { | ||
val stream: InputStream = Config.javaClass.getResourceAsStream("/icon.png") | ||
?: throw RuntimeException("Corrupted jar resources!") | ||
Files.write(iconPath, stream.readAllBytes()) | ||
stream.close() | ||
} | ||
Viken.init() | ||
val icon = VikenImage(iconPath) | ||
val window = Viken.createSync(800, 800, "Armitage ReWrite") | ||
requireNotNull(window) { "Could not create Window!" } | ||
window.setIconSync(icon.convertToIcon()) | ||
window.showSync() | ||
Viken.loop() | ||
while (conn.consoleActive()) { | ||
Thread.onSpinWait() | ||
} | ||
Thread.sleep(20000) //run for 20 seconds for testing | ||
Viken.cleanup() | ||
icon.dispose() | ||
} | ||
|
||
} |
119 changes: 119 additions & 0 deletions
119
src/main/kotlin/com/wavproductions/www/armitage/Metasploit.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package com.wavproductions.www.armitage | ||
|
||
import java.io.Closeable | ||
import java.io.IOException | ||
import java.net.InetAddress | ||
import java.net.Socket | ||
import java.security.InvalidParameterException | ||
import javax.net.ssl.SSLSocketFactory | ||
|
||
class Metasploit : Closeable { | ||
private var console: Process? | ||
private var rpc: Socket? = null //will be a direct connection, so most likely a socket | ||
|
||
init { | ||
console = null | ||
} | ||
|
||
fun load( | ||
username: String = "msf", | ||
password: String = "pass", | ||
ip: InetAddress = InetAddress.getLoopbackAddress(), | ||
port: Int = 55552, | ||
ssl: Boolean = false, | ||
program: String? = null, | ||
local: Boolean = true, | ||
debug: Boolean = false | ||
) { | ||
if (port < 0 || port > 65535) { | ||
throw InvalidParameterException("port is invalid! Valid values are 0-65535") | ||
} | ||
var connected = false | ||
try { | ||
connected = attemptConnect(username, password, ip, port, ssl) | ||
} catch (ignored: Exception) { | ||
if (debug) { | ||
ignored.printStackTrace() | ||
} | ||
} | ||
if (!connected && local) { | ||
val location = program ?: locateMetasploit() ?: throw NullPointerException("Unable to locate console!") | ||
val builder = ProcessBuilder(location) | ||
builder.redirectOutput(ProcessBuilder.Redirect.PIPE) | ||
builder.redirectError(ProcessBuilder.Redirect.PIPE) | ||
if (debug) { | ||
builder.redirectOutput(ProcessBuilder.Redirect.INHERIT) | ||
builder.redirectError(ProcessBuilder.Redirect.INHERIT) | ||
} | ||
builder.redirectInput(ProcessBuilder.Redirect.PIPE) | ||
console = builder.start() | ||
//await startup | ||
console?.outputStream?.write("load msgrpc ServerHost='${ip.hostAddress}' ServerPort=$port User='$username' Pass='$password' SSL=$ssl\n".toByteArray()) | ||
console?.outputStream?.flush() | ||
//await rpc start | ||
connected = attemptConnect(username, password, ip, port, ssl) | ||
} | ||
if (!connected) { | ||
throw IOException("Failed to contact the RPC server") | ||
} | ||
} | ||
|
||
private fun locateMetasploit(): String? { | ||
val builder = ProcessBuilder("which", "msfconsole") //linux lookup for now... might add windows later | ||
builder.redirectOutput(ProcessBuilder.Redirect.PIPE) | ||
builder.redirectError(ProcessBuilder.Redirect.PIPE) | ||
builder.redirectInput(ProcessBuilder.Redirect.PIPE) | ||
val which = builder.start() | ||
while (which.isAlive) { | ||
Thread.onSpinWait() | ||
} | ||
if (String(which.errorStream.readAllBytes()).contains("which: no")) { | ||
return null | ||
} | ||
val programs = String(which.inputStream.readAllBytes()).split("\n") | ||
var selected: String? = null | ||
for (x in programs) { | ||
if (x.endsWith("msfconsole")) { //select first program located by which | ||
selected = x | ||
break | ||
} | ||
} | ||
return selected | ||
} | ||
|
||
private fun attemptConnect(username: String, password: String, ip: InetAddress, port: Int, ssl: Boolean): Boolean { | ||
val socket = if (ssl) SSLSocketFactory.getDefault().createSocket(ip, port) else Socket(ip, port) | ||
if (socket.isConnected) { | ||
rpc = socket | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
fun consoleActive(): Boolean { | ||
return console?.isAlive ?: false | ||
} | ||
|
||
fun startRPC(): Boolean { | ||
if (!consoleActive()) { //make sure console is active to init rpc | ||
return false | ||
} | ||
return false //rpc failed to init! | ||
} | ||
|
||
fun readRPC(): ByteArray { | ||
return rpc?.inputStream?.readAllBytes() ?: ByteArray(0) | ||
} | ||
|
||
fun sendRPCCommand(command: ByteArray, flush: Boolean = false) { | ||
rpc?.outputStream?.write(command) | ||
if (flush) { | ||
rpc?.outputStream?.flush() | ||
} | ||
} | ||
|
||
override fun close() { //destroy resources | ||
console?.destroyForcibly() | ||
rpc?.close() | ||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
src/test/kotlin/com/wavProductions/www/armitage/TestPlaceholder.kt
This file was deleted.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
src/test/kotlin/com/wavproductions/www/armitage/TestPlaceholder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package com.wavproductions.www.armitage | ||
|