2011-11-27 63 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

關鍵是要證明這個系統不是很聰明,而且可以被熟練的攻擊者輕易地愚弄。我不確定它會檢測到它。但我一定會嘗試。謝謝你的回答! –