2011-11-27 68 views
11

我的公司有一个非常严格的与工作有关的内联网,网络有一个允许文件输入和输出的门户。门口的安全性不允许特殊类型的文件(仅限于* .txt,* .doc等),即使在这些特定类型的文件中,它也会搜索认可该文件真的是那种类型的模式。 (你不能简单地将一个* .zip文件伪装成一个* .doc文件)。如何使用JavaScript解码来自base64编码的文件

作为一个安全项目,我被告知找到一种方法来绕过这个系统,并插入一个C语言的.exe文件那说'Hello World'

我的想法是将扩展名更改为.txt,并对base64进行编码,以便系统更易于接受。问题是,如何解码它。在外部非常容易,PHP或任何其他体面的语言都可以为我做到这一点。但是,在那里,我唯一能够访问的真正语言是JavaScript(在IE6上,也许在MAYBE上,在IE8上)。

所以问题如下,我可以使用JavaScript从文件系统读取文件,解码并写回来吗?或者至少为我显示结果?

请注意,我不要求解码/编码的消息,这一个很容易,我期待解码编码文件

谢谢。

+1

您想解码用户下载并保存到磁盘的文件吗?恐怕这是不可能的,但是如果支持的话,您可以使用https通过防火墙/代理隧道传输文件。 – x4u

+0

@Truth:也许你可以使用AIR:检查File API,http://www.google.it/url?sa=t&rct=j&q=javascript%20air&source=web&cd=1&ved=0CCAQFjAA&url=http%3A%2F% 2Fonair.adobe.com%2Ffiles%2FAIRforJSDevPocketGuide.pdf&ei = xQHSTqr0GIa6hAe8wu3WDQ&usg = AFQjCNGp5Z1AIQMNG1bW0502qF_4JaUSjw&sig2 = a-dnLJi2vlcg847htO9Vwg&cad = rja – AsTheWormTurns

+0

这是一个内部系统。我很确定那里没有AIR。我会检查一下。 –

回答

6

JSON可能是您正在寻找的答案。它实际上可以做到这一点。

  1. 以JSON格式对您的txt文件进行编码。这很可能为它通过贵公司的大门口保安

    var myJsonData = { "text" : "SGVsbG8sIHdvcmxkIQ==" }; // <-- base64 for "Hello, world!" 
    
  2. 使用纯HTML脚本语法

    <script src="hello.txt" type="text/javascript"> </script> 
    
  3. 这就是它导入您的txt文件!现在,您可以访问使用语法JSON对象:

    alert(myJsonData.text); 
    
  4. 要完成你的工作,得到this简单的Javascript的base64解码器。

  5. 你完成了。下面是我使用的(很简单)的代码:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
    <html> 
        <head> 
        <meta http-equiv="content-type" content="text/html; charset=windows-1250"> 
        <meta name="generator" content="PSPad editor, www.pspad.com"> 
        <title></title> 
    
        <script src="base64utils.js" type="text/javascript"> </script> 
        <script src="hello.txt" type="text/javascript"> </script> 
    
        <script type="text/javascript"> 
        function helloFunction() { 
        document.getElementById("hello").innerHTML = decode64(myJsonData.text); 
        } 
        </script> 
    
        </head> 
        <body onload="helloFunction();"> 
        <p id="hello"></p> 
        </body> 
    </html> 
    
+0

neat!会在IE6上工作吗? –

+0

我已经测试过了在Ubuntu中使用winetricks运行IE6。它的工作原理。我不知道它是否也可以在你的环境中工作,但恕我直言,这是值得尝试的。 – loscuropresagio

+0

我会尝试。太糟糕了,赏金将在此之前过期:X –

6

只使用JavaScript(即没有AIR等插件),浏览器不允许访问文件系统。不仅无法将文件写入磁盘,而且甚至无法读取它 - 浏览器对此非常严格,谢天谢地。

+2

刚刚建议的朋友如果安装了闪光灯,它可能会工作。 – Jeff

+0

它已安装。我不知道哪个版本,但我出租车检查。如果有,请添加闪存解决方案。 –

+0

对不起,我不熟悉闪光自己 - 你可能有更多的运气问这个问题的另一个问题。 – Jeff

3

你不能在浏览器中直接使用JS,安全上下文和DOM不允许文件系统访问。

你不能用当前版本的flash来做到这一点,旧版本(pre 7 IIRC)有一些安全缺陷,允许文件系统访问。

您可以使用自定义插件以及可能签名的Java小程序或COM(ActiveX组件,仅限IE)执行此操作。

我建议与IT部门合作,关于您的企业内部网以打开本案例中所需的上下文/权限,因为这可能是您想要的最短路径。或者,您可以创建一个命令行实用程序,以轻松加密/解密由公用密钥签名的给定文件。

+0

关键是要“打入”,我不应该和一个内部人员一起工作,因为这会消除这个问题,你能解释一下关于命令行工具的更多信息吗? –

2

这一切都取决于你如何能得到的文件如果您有base-64编码EXE为.txt,您可以轻松使用Flash! 我不太清楚你将如何实现这一点,但你可以使用flex将文件加载到flash和as3中。

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> 

    <mx:Script> 
     <![CDATA[ 
      import flash.net.FileReference; 
      import flash.net.FileFilter; 

      import flash.events.IOErrorEvent; 
      import flash.events.Event; 

      import flash.utils.ByteArray; 

      //FileReference Class well will use to load data 
      private var fr:FileReference; 

      //File types which we want the user to open 
      private static const FILE_TYPES:Array = [new FileFilter("Text File", "*.txt;*.text")]; 

      //called when the user clicks the load file button 
      private function onLoadFileClick():void 
      { 
       //create the FileReference instance 
       fr = new FileReference(); 

       //listen for when they select a file 
       fr.addEventListener(Event.SELECT, onFileSelect); 

       //listen for when then cancel out of the browse dialog 
       fr.addEventListener(Event.CANCEL,onCancel); 

       //open a native browse dialog that filters for text files 
       fr.browse(FILE_TYPES); 
      } 

      /************ Browse Event Handlers **************/ 

      //called when the user selects a file from the browse dialog 
      private function onFileSelect(e:Event):void 
      { 
       //listen for when the file has loaded 
       fr.addEventListener(Event.COMPLETE, onLoadComplete); 

       //listen for any errors reading the file 
       fr.addEventListener(IOErrorEvent.IO_ERROR, onLoadError); 

       //load the content of the file 
       fr.load(); 
      } 

      //called when the user cancels out of the browser dialog 
      private function onCancel(e:Event):void 
      { 
       trace("File Browse Canceled"); 
       fr = null; 
      } 

      /************ Select Event Handlers **************/ 

      //called when the file has completed loading 
      private function onLoadComplete(e:Event):void 
      { 
       //get the data from the file as a ByteArray 
       var data:ByteArray = fr.data; 

       //read the bytes of the file as a string and put it in the 
       //textarea 
       outputField.text = data.readUTFBytes(data.bytesAvailable); 

       //clean up the FileReference instance 

       fr = null; 
      } 

      //called if an error occurs while loading the file contents 
      private function onLoadError(e:IOErrorEvent):void 
      { 
       trace("Error loading file : " + e.text); 
      } 

     ]]> 
    </mx:Script> 

    <mx:Button label="Load Text File" right="10" bottom="10" click="onLoadFileClick()"/> 
    <mx:TextArea right="10" left="10" top="10" bottom="40" id="outputField"/> 

</mx:Application> 

对其进行解码,考虑http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/utils/Base64Decoder.html

1

如果安全系统会扫描文件中的图案,这是不太可能,它会忽略在文件Base64编码的文件或Base64编码的内容。电子邮件附件是以base64编码的,如果系统性能良好,它将扫描可能有害的电子邮件附件,即使它们被命名为.txt。几乎可以肯定地认识到EXE file的base64编码开始。所以ISTM你问的是错误的问题。

+1

关键是要证明这个系统不是很聪明,而且可以被熟练的攻击者轻易地愚弄。我不确定它会检测到它。但我一定会尝试。谢谢你的回答! –