Created
March 31, 2016 09:06
-
-
Save trevorsibanda/971acb12a5d8b435907363c4f1500143 to your computer and use it in GitHub Desktop.
Scala traverse path and print file hashes
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
//Just for fun | |
//Directory Traversal | |
import java.io._ | |
import scala.io._ | |
import java.security.MessageDigest | |
object Traverse | |
{ | |
def md5(s: String )= | |
{ | |
MessageDigest.getInstance("MD5").digest( s.getBytes ).map("%02X".format(_)).mkString | |
} | |
def sha(s: String )= | |
{ | |
MessageDigest.getInstance("SHA").digest( s.getBytes ).map("%02X".format(_)).mkString | |
} | |
def main( args: Array[String]) | |
{ | |
println("[+] Trevor Sibanda Learning Scala Directory Traversal") | |
println("[-] Enter directory to start from: ") | |
val path = "/etc/"//Console.readLine | |
val root = new File(path) | |
if( ! root.exists || ! root.isDirectory ) | |
{ | |
println("[!] Entered path is not a directory") | |
} | |
for( file <- root.listFiles().filter(_.canRead ).filter( _.isFile ).map( _.getAbsolutePath ) ) | |
{ | |
val buffer = Source.fromFile(file).mkString | |
println("[-] %s\tMD5:%s \tSHA:%s".format(file, md5(buffer) , new String( sha(buffer) ) ) ) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment