加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl base64解码

发布时间:2020-12-16 00:04:57 所属栏目:大数据 来源:网络整理
导读:看phrack的时候,作者的代码有时不是以plain text的格式粘贴出来,有时使用了base64的编码,有时使用的uuencode格式的编码。 要识别base64还是uuencode编码可以看文件的第一行,如果明确了base64的话,那么就是base64编码,否则很有可能就是uuencode。 于是

看phrack的时候,作者的代码有时不是以plain text的格式粘贴出来,有时使用了base64的编码,有时使用的uuencode格式的编码。

要识别base64还是uuencode编码可以看文件的第一行,如果明确了base64的话,那么就是base64编码,否则很有可能就是uuencode。

于是写了一个小脚本用来把base64/uuencode转换成tar.gz(大多数情况下都是这种格式)的。

使用方法:

将文件粘贴到记事本中保存之。然后运行脚本。

如果是UUEncode的编码, 则begin和end也要保存。

然后运行

perl decode.pl -s source.txt -d dest.txt -c base64

perl ?decode.pl -s a.txt ?-c UU


===========================================================================================

decode.pl

===========================================================================================

#!/usr/bin/perl -w use strict; use warnings; use MIME::Base64; use Convert::UU qw(uudecode); use Getopt::Long; my $srcfile; my $dstfile; my $help; my $encode; GetOptions( ? ? ? ? 'h|help' ? ? ? ?=> $help,? ? ? ? 's=s' ? ? ? ? ? => $srcfile,? ? ? ? 'd=s' ? ? ? ? ? => $dstfile,? ? ? ? 'c=s' ? ? ? ? ? => $encode); sub help{ ? ? ? ? print <<_EOT_; 'perl $0 -s source.txt -d dest.txt -c base64' 'perl $0 -s source.txt -c UU' only decode base64 or UU when decoding base64,you should specify the dst file name _EOT_ ? ? ? ? exit; } help() if $help; help() unless $srcfile; help() unless ($encode eq "base64") or ($encode eq "UU"); print "$srcfile doesn't existn" unless -e $srcfile; sub main_base64{ ? ? ? ? my ($src,$dst) = @_; ? ? ? ? my $in; ? ? ? ? my $out; ? ? ? ? my $string; ? ? ? ? my $result; ? ? ? ? help() unless $dst; ? ? ? ? open $in,$src; ? ? ? ? open $out,">",$dst; ? ? ? ? while(<$in>){ ? ? ? ? ? ? ? ? chomp; ? ? ? ? ? ? ? ? $string = $string.$_; ? ? ? ? } # ? ? ? if($enc eq "base64"){ ? ? ? ? $result = decode_base64($string); # ? ? ? }elsif($enc eq "UU"){ # ? ? ? ? ? ? ? $result = uudecode($string,"vlc_lulz_v0.1.tar.gz",644 ); # ? ? ? } ? ? ? ? print $out $result; ? ? ? ? close($in); ? ? ? ? close($out); ? ? ? ? print "Donen"; ? ? ? ? exit; } sub main_uu{ ? ? ? ? my ($src,$dst) = @_; ? ? ? ? my $in; ? ? ? ? my $out; ? ? ? ? open $in,$src; ? ? ? ? my($string,$filename,$mode) = uudecode($in); ? ? ? ? open $out,$filename; ? ? ? ? print $out $string; ? ? ? ? close($in); ? ? ? ? close($out); ? ? ? ? print "Donen"; ? ? ? ? exit; } main_base64($srcfile,$dstfile)if $encode eq "base64"; main_uu($srcfile,$dstfile) if $encode eq "UU";

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读