Regex: (?:([\w ]*)[\/\\])?([\w ]*)%([\S \t]*)
Sample Code:
#!/usr/bin/env ruby def parseSMBCreds(creds) domain, user, password = creds.match(/(?:([\w ]*)[\/\\])?([\w ]*)%([\S \t]*)/).captures end domain,user,password = parseSMBCreds('lolwut/Jim Bo%Pas!@#$%^&*()<>?:"') puts "User Domain: #{domain}" puts "Username: #{user}" puts "Password: #{password}" domain,user,password = parseSMBCreds('lolwut/JimBo%Pas!@#$%^&*()<>?:"') puts "User Domain: #{domain}" puts "Username: #{user}" puts "Password: #{password}" domain,user,password = parseSMBCreds('JimBo%Pas!@#$%^&*()<>?:"') puts "User Domain: #{domain}" puts "Username: #{user}" puts "Password: #{password}"
Run the script and view the results with different formats of creds:
There you go, feel free to use the regex/code in your own scripts to make your life easier.
No comments:
Post a Comment