返回列表 回复 发帖

BASE64编码工具源代码

信息来源:RinGz BbS

在做一个木马的时候需要把一些东西进行base64编码,可是我手头没有邮件工具(事后才想起把QQMAIL给忘了)。于是就顺手用perl写了一个base64的转换程序。。有的时候感觉perl真是个好东西,大家有机会可以学学,确实不错的。。。

该工具可以对任意格式的文件进行base64编码。原代码如下(由于是顺手写来的,格式上都没有怎么讲究,你们就讲究看了!
  1. use MIME::Base64;
  2. if (@ARGV==0) {
  3. &usage;
  4. exit(0);}
  5. $action=$ARGV[0] || die "you must specify an action to do !\n";
  6. $sourcefile=$ARGV[1] || die "you must specify the source file encoded or decoded!\n";
  7. $destfile=$ARGV[2] || die "you must specify the dest file \n";
  8. if($action=~/^e/i)
  9. {
  10. open(SF,"$sourcefile") || die "open source file failed!\n";
  11. open(DF,">$destfile") || die "open dest file failed\n";
  12. print "reading source file";
  13. binmode(SF);
  14. my @alldata=<SF>;
  15. die "reading source file error!\n" unless(@alldata);
  16. print ".........................OK\n";
  17. print "writing dest file";
  18. foreach $dataencoded (@alldata) {
  19. print DF encode_base64($dataencoded);}
  20. print ".........................OK\n";
  21. close(SF);
  22. close(DF);
  23. }

  24. if ($action=~/^d/i) {
  25. open(SF,"$sourcefile") || die "open source file failed!\n";
  26. open(DF,">$destfile") || die "open dest file failed\n";
  27. print "reading source file";
  28. my @alldata=<SF>;
  29. die "reading source file error!\n" unless(@alldata);
  30. print ".........................OK\n";
  31. print "writing dest file";
  32. binmode(DF);
  33. foreach $dataencoded (@alldata) {
  34. print DF decode_base64($dataencoded);}
  35. print ".........................OK\n";
  36. close(SF);
  37. close(DF);
  38. }
  39. sub usage
  40. {print "\t Base64 Encode/Decode program\n";
  41. print " \t written by [email]superlone@ringz.org[/email]\n";
  42. print "Usage:\n";
  43. print "\t Base64.pl <aciton> <souce file> <dest file>\n\n";
  44. print "Action:\n";
  45. print "\te\t to encode\n";
  46. print "\td\t to decode\n";
  47. }
复制代码
用法:
编码:
base64.pl e 原文件 目标文件
解码:
base64.pl d 原文件 目标文件

H:\tools\asist>base64.pl e sqlcmd.exe test.txt
reading source file.........................OK
writing dest file.........................OK

H:\tools\asist>base64.pl d test.txt sss.ex
reading source file.........................OK
writing dest file.........................OK

H:\tools\asist>base64.pl d test.txt sss.exe
reading source file.........................OK
writing dest file.........................OK

希望对需要的朋友能有所帮助!
返回列表