diff options
author | unethical <une@thi.cal> | 2019-05-03 03:38:02 +0000 |
---|---|---|
committer | unethical <une@thi.cal> | 2019-05-03 03:38:02 +0000 |
commit | 2caea9e0f1cf09e37ea4c5f2b80458fb0c5a2997 (patch) | |
tree | db5b268fe3c2cbaaab4a6a7c28b65de8101a636e /tool | |
parent | f95683fb61ba428636a38e54ce9ab02dfadf4506 (diff) | |
download | cloudflare-tor-2caea9e0f1cf09e37ea4c5f2b80458fb0c5a2997.tar cloudflare-tor-2caea9e0f1cf09e37ea4c5f2b80458fb0c5a2997.tar.gz cloudflare-tor-2caea9e0f1cf09e37ea4c5f2b80458fb0c5a2997.tar.lz cloudflare-tor-2caea9e0f1cf09e37ea4c5f2b80458fb0c5a2997.tar.xz cloudflare-tor-2caea9e0f1cf09e37ea4c5f2b80458fb0c5a2997.zip |
Add 'tool/irssi_cf_alturl.pl'
Diffstat (limited to 'tool')
-rw-r--r-- | tool/irssi_cf_alturl.pl | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/tool/irssi_cf_alturl.pl b/tool/irssi_cf_alturl.pl new file mode 100644 index 00000000..22264882 --- /dev/null +++ b/tool/irssi_cf_alturl.pl @@ -0,0 +1,120 @@ +#!/usr/bin/perl -w +# This Irssi script automatically check incoming http/https links +# and replace it to archive one if it is MITMed. +#--------------------------------------------------------------------- +use strict; +use vars qw($VERSION %IRSSI); + +$VERSION = "20190501"; + +%IRSSI = ( + authors => "Anonymous", + contact => 'nobody@cloudflare-tor.nab', + name => "irssi_cf_alturl.pl", + description => "Cloudflare URL replacer", + license => "WTFPL", + changed => "$VERSION" +); + +use Irssi; +use Irssi::Irc; +use LWP::Simple; +use LWP::UserAgent; + +my ( $min_url_length, $send_to_channel, $debug, $channel_list ); + +sub setuphandler { + $send_to_channel = 1; + $channel_list = ''; + my $old_min_url_length = $min_url_length; + $min_url_length = 0; + my $old_debug = $debug; + $debug = 0; +} + +sub GotUrl { + my ( $server, $data, $nick, $addr, $target ) = @_; + if ( !$server || !$server->{connected} ) { + Irssi::print("Not connected to server"); + return; + } + $data =~ s/^\s+//; + $data =~ s/\s+$//; + my @urls = (); + my ( $url, $a, $return, $char, $ch, $result, $choice ) = ""; + my $same = 0; + my $sitewas = "t"; + my @chars = (); + return unless ( ( $data =~ /\bhttp\:/ ) || ( $data =~ /\bhttps\:/ ) ); + deb("$target triggered GotUrl() with url: $data"); + + foreach ( split( /\s/, $data ) ) { + if ( ( $_ =~ /^http\:/ ) || ( $_ =~ /^https\:/ ) ) { + foreach $a (@urls) { + if ( $_ eq $a ) { + $same = 1; + next; + } + } + if ( $same == 0 ) { + $same = 0; + push( @urls, $_ ); + } + } + } + foreach (@urls) { + @chars = split( //, $_ ); + foreach $char (@chars) { + if ( $char !~ /[A-Za-z0-9]/ ) { + $ch = sprintf( "%%%02x", ord($char) ); + $result .= $ch; + } + else { + $result .= $char; + } + } + $choice = 'searxesmitmdb'; + deb("mitmtest(\$server, $target, $result)"); + mitmtest( $server, $target, $result ); + } + return; +} + +sub mitmtest { + my ( $server, $chan, $longurl ) = @_; + my ($fqdn) = $longurl =~ m!(https?://[^:/]+)!; + my ( $junk, $fqdn ) = split( /\/\//, $fqdn, 2 ); + my $url = 'https://searxes.danwin1210.me/collab/open/ismitm.php?f=' . $fqdn; + deb("getting url:($url)"); + my $browser = LWP::UserAgent->new; + $browser->agent("cloudflare cflare_alt.pl"); + my $response = $browser->get($url); + my $scanned_url = $response->content; +## if the array[1] is true => it is MITM + if ( $scanned_url == '[true,true]' ) { + $scanned_url = 'https://web.archive.org/web/' . $longurl; + } + else { + $scanned_url = $longurl; + } + if ( $response->is_success ) { + if ( $send_to_channel == 1 ) { + $server->command("msg $chan $scanned_url"); + } + else { + $server->print( "$chan", "$scanned_url", MSGLEVEL_CLIENTCRAP ); + } + } + else { + deb("ERROR: service is down or not pingable"); + } +} + +sub deb($) { + Irssi::print(shift) if ( $debug == 1 ); +} + +setuphandler(); +Irssi::signal_add( "setup changed", "setuphandler" ); +Irssi::signal_add_last( "message public", "GotUrl" ); +Irssi::signal_add_last( "ctcp action", "GotUrl" ); |