Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: BigBear en 11 Noviembre 2016, 14:20 pm



Título: [Perl] DH Twitter Locator 0.6
Publicado por: BigBear en 11 Noviembre 2016, 14:20 pm
Un script en Perl para scanear los tweets de cualquier usuario , basado en la idea original de "tinfoleak by Vicente Aguilera Diaz"

Funciones :

  • Extrae informacion del perfil
  • Scanea los tweets en busca de apps y locations
  • Permite cargar las localizaciones en google maps
  • Guarda todo en logs

El codigo :

Código
  1. # !usr/bin/perl
  2. # DH Twitter Locator 0.6
  3. # (C) Doddy Hackman 2016
  4. # Credits :
  5. # Based in idea original of : tinfoleak by Vicente Aguilera Diaz
  6.  
  7. use LWP::UserAgent;
  8. use IO::Socket::SSL;
  9. use HTTP::Request::Common;
  10. use JSON;
  11. use Data::Dumper;
  12. use MIME::Base64;
  13. use Date::Parse;
  14. use DateTime;
  15. use Getopt::Long;
  16. use Color::Output;
  17. Color::Output::Init;
  18.  
  19. my $consumer_key = "IQKbtAYlXLripLGPWd0HUA";
  20. my $consumer_secret = "GgDYlkSvaPxGxC4X8liwpUoqKwwr3lCADbz8A7ADU";
  21.  
  22. my $bearer_token = "$consumer_key:$consumer_secret";
  23. my $bearer_token_64 = encode_base64($bearer_token);
  24.  
  25. my $nave = LWP::UserAgent->new(ssl_opts => {verify_hostname => 0,SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE});
  26. $nave->agent(
  27. "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0"
  28. );
  29. $nave->timeout(5);
  30.  
  31. GetOptions(
  32. "profile"   => \$profile,
  33. "apps"   => \$apps,
  34.    "locations"  => \$locations,
  35.    "username=s"   => \$username,
  36.    "count=i"   => \$count,
  37.    "savefile=s"  => \$savefile,
  38. );
  39.  
  40. head();
  41.  
  42. if ($profile) {
  43. if($profile && $username) {
  44. search_profile($username);
  45. } else {
  46. sintax();
  47. }
  48. }
  49. if ($apps) {
  50. if($apps && $username && $count) {
  51. search_apps($username,$count);
  52. } else {
  53. sintax();
  54. }
  55. }
  56. if ($locations) {
  57. if($locations && $username && $count) {
  58. search_locations($username,$count);
  59. } else {
  60. sintax();
  61. }
  62. }
  63. if(!$profile and !$apps and !$locations) {
  64. sintax();
  65. } else {
  66. if($savefile) {
  67. printear_logo("\n[+] Logs $savefile saved\n");
  68. }
  69. }
  70.  
  71. copyright();
  72.  
  73. # Functions
  74.  
  75. sub search_profile {
  76. my ($username) = @_;
  77.  
  78. printear_titulo("\n[+] Loading Profile in Username : ");
  79. print $username." ...\n\n";
  80.  
  81. #my $code = toma("http://localhost/twitter/getuser.php");
  82. my $code = get_code("https://api.twitter.com/1.1/users/show.json?screen_name=".$username);
  83.  
  84. my $resultado = JSON->new->decode($code);
  85.  
  86. my $screen_name = $resultado->{"screen_name"};
  87. if($screen_name eq "") {
  88. $screen_name = "Not Found";
  89. }
  90. my $name = $resultado->{"name"};
  91. if($name eq "") {
  92. $name = "Not Found";
  93. }
  94. my $id = $resultado->{"id_str"};
  95. if($id eq "") {
  96. $id = "Not Found";
  97. }
  98. my $created = parse_date($resultado->{"created_at"});
  99. if($created eq "") {
  100. $created = "Not Found";
  101. }
  102. my $followers = $resultado->{"followers_count"};
  103. if($followers eq "") {
  104. $followers = "Not Found";
  105. }
  106. my $tweets_count = $resultado->{"statuses_count"};
  107. if($tweets_count eq "") {
  108. $tweets_count = "Not Found";
  109. }
  110. my $location = $resultado->{"location"};
  111. if($location eq "") {
  112. $location = "Not Found";
  113. }
  114. my $description = $resultado->{"description"};
  115. if($description eq "") {
  116. $description = "Not Found";
  117. }
  118. my $url = $resultado->{"url"};
  119. if($url eq "") {
  120. $url = "Not Found";
  121. }
  122. my $profile_image = $resultado->{"profile_image_url"};
  123. if($profile_image eq "") {
  124. $profile_image = "Not Found";
  125. }
  126.  
  127. printear("Screen Name : ");
  128. print $screen_name."\n";
  129. printear("Username : ");
  130. print $name."\n";
  131. printear("ID : ");
  132. print $id."\n";
  133. printear("Created at : ");
  134. print $created."\n";
  135. printear("Followers : ");
  136. print $followers."\n";
  137. printear("Tweets count : ");
  138. print $tweets_count."\n";
  139. printear("Location : ");
  140. print $location."\n";
  141. printear("Description : ");
  142. print $description."\n";
  143. printear("URL : ");
  144. print $url."\n";
  145. printear("Profile Image : ");
  146. print $profile_image."\n";
  147.  
  148. printear_titulo("\n[+] Profile Loaded\n");
  149.  
  150. if($savefile) {
  151. savefile($savefile,"\n[+] Loading Profile in Username : $username\n");
  152. savefile($savefile,"Screen Name : $screen_name");
  153. savefile($savefile,"Username : $name");
  154. savefile($savefile,"ID : $id");
  155. savefile($savefile,"Created at : $created");
  156. savefile($savefile,"Followers : $followers");
  157. savefile($savefile,"Tweets count : $tweets_count");
  158. savefile($savefile,"Location : $location");
  159. savefile($savefile,"Description : $description");
  160. savefile($savefile,"URL : $url");
  161. savefile($savefile,"Profile Image : $profile_image");
  162. savefile($savefile,"\n[+] Profile Loaded");
  163. }
  164.  
  165. #for my $number(1..5) {
  166. # sleep(1);
  167. # printear_logo("number : ");
  168. # printear_titulo($number."\r");
  169. #}
  170. #printear_titulo("Number : Finished\n");
  171. }
  172.  
  173. sub search_apps {
  174. my($username,$count) = @_;
  175.  
  176. printear_titulo("\n[+] Searching Apps in Username : ");
  177. print $username." ...\n\n";
  178.  
  179. #my $code = toma("http://localhost/twitter/timeline.php");
  180. my $code = get_code("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$username."&include_rts=True&count=".$count);
  181.  
  182. my $resultado = JSON->new->decode($code);
  183.  
  184. my @resultado = @$resultado;
  185.  
  186. my $i = 0;
  187.  
  188. if(int(@resultado) eq "0") {
  189. printear_rojo("[-] Tweets not found\n");
  190. } else {
  191. printear("[+] Tweets found : ");
  192. print int(@resultado)."\n\n\n";
  193. printear("  Tweet\t\t Date\t\t   Apps\n");
  194. print "  -----------------------------------------------------\n\n";
  195.  
  196. if($savefile) {
  197. savefile($savefile,"\n[+] Searching Apps in Username : $username\n");
  198. savefile($savefile,"[+] Tweets found : ".int(@resultado)."\n");
  199. savefile($savefile,"  Tweet\t\t Date\t\t   Apps\n");
  200. savefile($savefile,"  -----------------------------------------------------\n");
  201. }
  202.  
  203. for my $result(@resultado) {
  204. $i++;
  205. my $source_split = $result->{"source"};
  206. if($source_split=~/>(.*)<\/a>/) {
  207. my $source = $1;
  208. my $datetime = parse_date($result->{"created_at"});
  209. if($source ne "") {
  210. printf("   %-5s %-22s %-15s\n", $i,$datetime,$source);
  211. if($savefile) {
  212. savefile($savefile,"   $i\t$datetime\t$source");
  213. }
  214. }
  215. }
  216. }
  217.  
  218. printear_titulo("\n\n[+] Apps Loaded\n");
  219.  
  220. if($savefile) {
  221. savefile($savefile,"\n[+] Apps Loaded\n");
  222. }
  223. }
  224.  
  225. }
  226.  
  227. sub search_locations {
  228. my($username,$count) = @_;
  229.  
  230. printear_titulo("\n[+] Searching Locations in Username : ");
  231. print $username." ...\n\n";
  232.  
  233. #my $code = toma("http://localhost/twitter/timeline.php");
  234. my $code = get_code("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$username."&include_rts=True&count=".$count);
  235.  
  236. my $resultado = JSON->new->decode($code);
  237.  
  238. my @resultado = @$resultado;
  239.  
  240. my $i = 0;
  241.  
  242. if(int(@resultado) eq "0") {
  243. printear_rojo("[-] Tweets not found\n");
  244. } else {
  245. printear("[+] Tweets found : ");
  246. print int(@resultado)."\n\n\n";
  247.  
  248. printear("  Tweet\t\t Date\t\t     Locations\n");
  249. print "  -----------------------------------------------------\n\n";
  250.  
  251. if($savefile) {
  252. savefile($savefile,"\n[+] Searching Locations in Username : $username\n");
  253. savefile($savefile,"[+] Tweets found : ".int(@resultado)."\n");
  254. savefile($savefile,"  Tweet\t\t Date\t\t   Locations\n");
  255. savefile($savefile,"  -----------------------------------------------------\n");
  256. }
  257.  
  258. for my $result(@resultado) {
  259. $i++;
  260. my $place = $result->{"place"}{"country"};
  261. my $coordinates1 = $result->{"geo"}{"coordinates"}[0];
  262. my $coordinates2 = $result->{"geo"}{"coordinates"}[1];
  263. my $datetime = parse_date($result->{"created_at"});
  264. if($place ne "") {
  265. my $data = "";
  266. if($coordinates1 ne "" && $coordinates2 ne "") {
  267. $data = $place." [".$coordinates1.",".$coordinates2."]";
  268. } else {
  269. $data = $place;
  270. }
  271. printf("   %-5s %-22s %-15s\n", $i,$datetime,$data);
  272. if($savefile) {
  273. savefile($savefile,"   $i\t$datetime\t$data");
  274. }
  275. }
  276. }
  277. printear_titulo("\n\n[+] Locations Loaded\n");
  278. if($savefile) {
  279. savefile($savefile,"\n[+] Locations Loaded\n");
  280. }
  281. }
  282.  
  283. }
  284.  
  285. # More Functions
  286.  
  287. sub get_token {
  288. my $code = $nave->request(POST(
  289. "https://api.twitter.com/oauth2/token",
  290. "Content-Type" => "application/x-www-form-urlencoded;charset=UTF-8",
  291. "Authorization" => "Basic $bearer_token_64",
  292. Content => { "grant_type" => "client_credentials" }
  293. ))->content;
  294. my $resultado = JSON->new->decode($code);
  295. my $token = $resultado->{"access_token"};
  296. return $token;
  297. }
  298.  
  299. sub get_code {
  300. my $url = shift;
  301. my $code = $nave->request(GET($url,"Authorization" => "Bearer " . get_token()))->content;
  302. return $code;
  303. }
  304.  
  305. sub parse_date {
  306.    my $date = shift;        
  307.    $time = str2time($date);    
  308.    my $datetime = DateTime->from_epoch(epoch => $time);
  309.    return $datetime->mdy("/")." ".$datetime->hms;
  310. }
  311.  
  312. sub toma {
  313.    return $nave->get( $_[0] )->content;
  314. }
  315.  
  316. sub savefile {
  317. my ($filename,$text) = @_;
  318. open( SAVE, ">>" . $filename );
  319. print SAVE $text . "\n";
  320. close SAVE;
  321. }
  322.  
  323. sub printear {
  324.    cprint( "\x036" . $_[0] . "\x030" );
  325. }
  326.  
  327. sub printear_logo {
  328.    cprint( "\x037" . $_[0] . "\x030" );
  329. }
  330.  
  331. sub printear_titulo {
  332.    cprint( "\x0310" . $_[0] . "\x030" );
  333. }
  334.  
  335. sub printear_rojo {
  336.    cprint( "\x034" . $_[0] . "\x030" );
  337. }
  338.  
  339. sub printear_azul {
  340.    cprint( "\x033" . $_[0] . "\x030" );
  341. }
  342.  
  343. sub sintax {
  344.    printear("\n[+] Sintax : ");
  345.    print "perl $0 <option> <value>\n";
  346.    printear("\n[+] Options : \n\n");
  347.    print "-profile : Show profile information\n";
  348.    print "-apps : List apps in tweets\n";
  349.    print "-locations : List locations in tweets\n";
  350.    print "-username <username> : Set username to find\n";
  351. print "-count <count> : Set count to find\n";
  352. print "-savefile <filename> : Save results\n";
  353.    printear("\n[+] Example : ");
  354.    print "perl dh_twitter_locator.pl -profile -apps -locations -username test -count 800 -savefile results.txt\n";
  355.    copyright();
  356. }
  357.  
  358. sub head {
  359.    printear_logo("\n-- == DH Twitter Locator 0.6 == --\n\n");
  360. }
  361.  
  362. sub copyright {
  363.    printear_logo("\n\n-- == (C) Doddy Hackman 2016 == --\n\n");
  364.    exit(1);
  365. }
  366.  
  367. #The End ?
  368.  

Un video con ejemplos de uso :

56J0Hko5TfA

Si quieren bajar el programa lo pueden hacer de aca :

SourceForge (https://sourceforge.net/projects/dh-twitter-locator/).
Github (https://github.com/DoddyHackman/DH_Twitter_Locator).

Eso seria todo.