【网络安全】某安全网关前端JS分析
一、前言
xxx是一款用于前端防御自動化工具的安全網關,核心代碼由服務器下發給客戶端執行,通過cookie將執行結果帶回,再根據js獲取的前端數據判斷用戶是否異常,完成安全檢測
二、代碼入口
js計算結果通過cookie傳給服務器,參數名為:8PHkpr8y、JF7cGtR5、SflKxwRJ
經過調試分析,代碼明文存放在ng_dynamic_defend文件中,核心邏輯位于尾部這幾行
三、讀取配置
get_global()函數讀取配置信息,放入_global_config中
window**.**config **=** 'eyJmaW5nZXIiOnsibmFtZSI6IkpGN2NHdFI1In0sImJvdCI6eyJlbmFibGVkIjp0cnVlLCJuYW1lIjoiOFBIa3ByOHkifSwic3VibWl0Ijp7ImVuYWJsZWQiOnRydWUsIm5hbWUiOiJVVmpES082biIsInVybCI6IiJ9LCJ0b2tlbiI6eyJlbmFibGVkIjp0cnVlLCJuYW1lIjoiU2ZsS3h3UkoiLCJ1cmwiOiJqc190ZXN0LmNvbTsiLCJpc19jaGVja191cmkiOnRydWUsImlzX2NoZWNrX2dldCI6dHJ1ZX0sImNvbnRlbnQiOnsiZW5hYmxlZCI6ZmFsc2UsIm5hbWUiOiJTZmxLeHdSSiIsImNvbmZ1c2VfdHlwZSI6IjAifSwic2NyaXB0Ijp7ImlzX2FudGlfZGVidWciOmZhbHNlfX0='**;** **!****function** **(**global**)** **{****function** _base64_parse**(**e**)** **{****return** CryptoJS**.**enc**.**Base64**.**parse**(**e**).**toString**(**CryptoJS**.**enc**.**Utf8**)****}****function** get_global**()** **{****var** e **=** _base64_parse**(**global**.**config**),**t **=** JSON**.**parse**(**e**);**_global_config **=** global**.**nY1vq7Gi **=** t**}** **}(**window**);***/** *{**"finger": {**"name": "JF7cGtR5"**},**"bot": {**"enabled": true,**"name": "8PHkpr8y"**},**"submit": {**"enabled": true,**"name": "UVjDKO6n",**"url": ""**},**"token": {**"enabled": true,**"name": "SflKxwRJ",**"url": "js_test.com;",**"is_check_uri": true,**"is_check_get": true**},**"content": {**"enabled": false,**"name": "SflKxwRJ",**"confuse_type": "0"**},**"script": {**"is_anti_debug": false**}* *}* **/*【點擊查看資料詳細】
四、數據采集
以下三個函數會使用到window對象來采集客戶端數據:
- get_tool_feature() 獲得工具特征
- get_browser_feature() 獲得瀏覽器特征
- get_fingerprint() 獲得瀏覽器指紋
1.get_tool_feature()
get_webdriver**()** *//window.navigator.webdriver* get_phantomjs**()** *//window.navigator.userAgent* get_bot**()** *//檢測關鍵字:'__webdriver_evaluate','__selenium_evaluate','__webdriver_script_function','__webdriver_script_func','__webdriver_script_fn','__fxdriver_evaluate','__driver_unwrapped','__webdriver_unwrapped','__driver_evaluate','__selenium_unwrapped','__fxdriver_unwrapped''_phantom','__nightmare','_selenium','callPhantom','callSelenium','_Selenium_IDE_Recorder'* get_navigator_for_tool**()** *//window.navigator.languages* get_canvas_for_tool**()** *//window.document.createElement('canvas').getContext* get_storage_for_tool**()** *//window.localStorage && window.sessionStorage* get_consol**()** *//window.console.log(1)* get_awvs**()** *//檢測關鍵字:'SimpleDOMXSSClass','MarvinHooks','MarvinPageExplorer','HashDOMXSSClass'* get_appscan**()** *//檢測關鍵字:'appScanSendReplacement','appScanOnReadyStateChangeReplacement','appScanLoadHandler','appScanSetPageLoaded'*2.get_browser_feature()
get_indexedDB**()** *//window.indexedDB* get_openDatabase**()** *//window.openDatabase* get_localStorage**()** *//window.localStorage* get_sessionStorage**()** *//window.sessionStorage* get_audio**()** *//window.AudioContext.destination* get_file**()** *//'object' == typeof File || 'function' == typeof File* isCanvasSupported**()** *//window.document.createElement('canvas').getContext* isWebGlSupported**()** *//window.WebGLRenderingContext || window.document.createElement('canvas').getContext('webgl')* get_plugins**()** *//window.navigator.plugins* get_languages**()** *//window.navigator.languages* get_platform**()** *//window.navigator.platform* get_cpuClass**()** *//_navigator.cpuClass* get_hardwareConcurrency**()** *//_navigator.hardwareConcurrency* get_namespaces**()** *//window.document.namespaces* get_documentMode**()** *//window.document.documentMode* get_ActivexObject**()** *//window.document.ActivexObject* get_StyleMedia**()** *//window.StyleMedia* get_opera**()** *//window.opera* get_firefox**()** *//'undefined' != typeof InstallTrigger* get_chrome**()** *//window.chrome* get_safari**()** *///constructor/i.test(window.HTMLElement) || '[object SafariRemoteNotification]' === (!window.safari || safari.pushNotification).toString()*3.get_fingerprint()
get_indexedDB**()** *//window.indexedDB* get_openDatabase**()** *//window.openDatabase* get_localStorage**()** *//window.localStorage* get_sessionStorage**()** *//window.sessionStorage* get_audio**()** *//window.AudioContext.destination* get_file**()** *//'object' == typeof File || 'function' == typeof File* get_canvas**()** *//window.document.createElement('canvas')* get_webgl**()** *//window..document.createElement('canvas').getContext('webgl')* get_webgl_render**()** *//window.document.createElement('canvas').getContext('webgl')* get_plugins**()** *//window.navigator.plugins* get_language**()** *//window.navigator.language || window.navigator.userLanguage || window.navigator.browserLanguage || window.navigator.systemLanguage ||* get_languages**()** *//window.navigator.languages* get_platform**()** *//window.navigator.platform* get_cpuClass**()** *//window.navigator.cpuClass* get_hardwareConcurrency**()** *//window.navigator.hardwareConcurrency* get_timezone_offset**()** *//(new Date).getTimezoneOffset()* get_timezone**()** *//window.Intl && window.Intl.DateTimeFormat* get_screen_ratio**()** *//window.screen.width / window.screen.height * 100* get_screen_resolution**()** *//window.screen.availHeight + 'X' + window.screen.availWidth + 'X' + window.screen.availLeft + 'X' + window.screen.availTop* get_touch_support**()** *//window.navigator.maxTouchPoints || window.navigator.msMaxTouchPoints* get_media_devices**()** *//window.navigator.mediaDevices && window.navigator.mediaDevices.enumerateDevices* get_battery**()** *//window.navigator.getBattery* get_adBlock**()** *//window.document.getElementsByClassName('adsbox') [0].offsetHeight* get_userAgent**()** *//window.navigator.userAgent*
4.數據處理
set_bot_cookie()、set_fingerprint()兩個函數分別將tool_feature、browser_feature與fingerprint加密寫入到cokie中,變量名為:8PHkpr8y、JF7cGtR5
1.set_bot_cookie()
2.set_fingerprint()
五、 事件監聽
1.a標簽
設置EventListenerEx()監聽,當頁面加載完成時觸發load_func(),對當前cookie執行base64編碼操作,并設置參數名為KBwtGA
**function** confuse_cookie**()** **{****var** e**;**_document**.**cookie **&&** **0** **!=** _global_config**.**content**.**enabled **&&** '1' **==** _global_config**.**content**.**confuse_type **&&** **(**e **=** _document**.**cookie**,** clearAllCookie**(),** CookieUtil**.**set**(**'KBwtGA'**,** btoa**(**e**)))** **}**當發生點擊事件時觸發a_click_handler(),對請求地址添加令牌,變量名為SflKxwRJ
replace_url()調用get_token()生成加密tonken
2.form表單
設置EventListenerEx()監聽,當發生表單事件時觸發form_hook(),調用get_submit()對表單內數據加密,參數名為UVjDKO6n,調用get_token()生成加密tonken,參數名為SflKxwRJ
3.ajax請求
當發生ajax事件時觸發ajax_hook(),對不同請求方式做了單獨處理
監聽到get請求時調用get_body_for_get()對args數據使用get_token()加密,監聽到post請求時調用get_body_for_post()對請求體get_submit()加密、對url使用replace_url()調用get_token()生成加密tonken
六、總結
xxx的核心代碼未經過加密或混淆以明文形式下發,格式化后通過調試分析比較容易弄清楚執行邏輯,代碼主要實現以下兩個功能:
采集window或者navigator的部分特征值,按位計算形成一個整數,再利用rc4算法加密,指紋特征存放在cookie中JF7cGtR5、工具特征存放在cookie中8PHkpr8y
設置a標簽、form表單、ajax請求監聽,觸發時對數據內容調用get_submit()使用rc4算法加密、對url調用get_token()使用rc4算法計算token令牌
總結
以上是生活随笔為你收集整理的【网络安全】某安全网关前端JS分析的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【安全漏洞】Struts2漏洞集合总结
- 下一篇: 某CMSV1.0代码审计