Last active
August 29, 2015 14:14
-
-
Save mpfund/59c84f08ebbb2ca54b80 to your computer and use it in GitHub Desktop.
brute force urls
This file contains hidden or 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
| extern crate hyper; | |
| extern crate getopts; | |
| use hyper::Client; | |
| use hyper::header::*; | |
| use getopts::{optopt,optflag,getopts,OptGroup}; | |
| use std::os; | |
| use std::old_io as io; | |
| struct AppSettings { | |
| wordlist:String, | |
| url: Option<String>, | |
| help: bool | |
| } | |
| fn main(){ | |
| let args = os::args(); | |
| let settings = read_arguments(&args); | |
| if settings.help { | |
| return; | |
| } | |
| if settings.url==None{ | |
| println!("no host name argument."); | |
| return; | |
| } | |
| let mut cd = os::getcwd().ok().expect("getcwd failed"); | |
| cd.push(settings.wordlist); | |
| let filescontent = io::File::open(&cd) | |
| .read_to_string() | |
| .unwrap(); | |
| let files:Vec<&str> = filescontent.as_slice() | |
| .split_str("\n") | |
| .collect(); | |
| let mut client = Client::new(); | |
| let mut urlstart = settings.url.unwrap(); | |
| for f in files.iter() { | |
| let mut url = urlstart.as_slice().trim().to_string(); | |
| let filename = f.trim(); | |
| if url.ends_with("/") && filename.starts_with("/"){ | |
| url.pop(); | |
| } | |
| if !url.ends_with("/")&& !filename.starts_with("/"){ | |
| url.push('/'); | |
| } | |
| url.push_str(filename.as_slice()); | |
| let mut res = match client.get(url.as_slice()) | |
| .header(Connection(vec![ConnectionOption::Close])) | |
| .send(){ | |
| Ok(k)=>k, | |
| Err(_)=> { | |
| println!("host refused connection/not responding 0"); | |
| continue; | |
| } | |
| }; | |
| let cLength = match res.read_to_string(){ | |
| Ok(k)=>k.len(), | |
| _ => -1 | |
| }; | |
| println!("url {} {} {}",url,res.status,cLength); | |
| } | |
| } | |
| fn read_arguments(args:&Vec<String>)->AppSettings{ | |
| let program = args[0].clone(); | |
| let opts = [ | |
| optopt("u", "url", "target host or domain name", "NAME"), | |
| optopt("w", "wordlist", "input wordlist", "NAME"), | |
| optflag("h", "help", "print this help menu") | |
| ]; | |
| let mut settings = AppSettings { | |
| wordlist : "dictionary.wl".to_string(), | |
| url : None, | |
| help: false | |
| }; | |
| let matches = match getopts(args.tail(),&opts){ | |
| Ok(m)=>{m} | |
| Err(f)=>{panic!(f.to_string())} | |
| }; | |
| if matches.opt_present("h") { | |
| print_usage(program.as_slice(),&opts); | |
| settings.help = true; | |
| } else{ | |
| let output = matches.opt_str("w"); | |
| if output != None { | |
| settings.wordlist = output.unwrap().to_string(); | |
| } | |
| let starturl = matches.opt_str("u"); | |
| if starturl != None { | |
| settings.url = Some(starturl.unwrap().to_string()); | |
| } | |
| } | |
| settings | |
| } | |
| fn print_usage(program: &str, _opts: &[OptGroup]) { | |
| println!("Usage: {} [options]", program); | |
| println!(" a wordlist."); | |
| println!("Output file name is output.txt."); | |
| println!(""); | |
| println!("-u\t\turl/domain name, e.g. google.com"); | |
| println!("-w\t\twordlist with subdomains. (default is subdomains.wl)"); | |
| println!("-h --help\tshow help."); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment