Programming/기본 (Baisc)
[Java][JS] Ajax 바이너리 Base64 업로드 유틸
YH.Dream
2022. 11. 20. 21:39
1. 개요
해당 소스는 방화벽 및 보안 장비 우회를 통한 업로드를 하기 위해 제작된 소스이다.
해당 소스는 특별한 일을 제외하고는 사용하는 것을 권하지 않으며, 또한 파일 용량이 큰 경우 String으로 변환된 사유로 인해 용량이 평균 2배로 늘어나는 점 . 고려해야한다.
2. 대상 장비 범위
1) IPS, IDS 장비
2) F/W in IPS 장비
3) FW 장비
4) 스팸 장비
3. 소스
1) 자바스크립트 Javascript
let param = {};
let file = $("#inputFile")[0].files[0];
let reader = new FileReader();
reader.readAsArrayBuffer(file);
reader.onload = function () {
let resultData = reader.result;
let bitArray = new Uint8Array(resultData, {
type: file.type
});
let encoded = btoa(String.fromCharCode.apply(null, bitArray));
console.log(encoded);
param.path = btoa($("#svPath").val());
param.content = encoded;
console.log(param);
$.ajax({
url: '/admin/manage/upload.do',
data: JSON.stringify(param, null, 4),
contentType: "application/json;",
dataType: "json",
type: 'POST',
success: function (data) {
alert("완료되었습니다.");
}, error: function () {
}
});
}
2) 자바 Java / Spring Based XML
@RequestMapping(value = "/admin/manage/upload.do", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> upload(Model model, @RequestBody Map<String, String> paramMap) throws IOException {
String path = new String(Base64.decodeBase64((paramMap.get("path"))));
byte[] content = Base64.decodeBase64(paramMap.get("content"));
File file = new File(path);
try {FileUtils.forceDelete(file); } catch (Exception e) {};
FileUtils.writeByteArrayToFile(file, content);
Map<String, String> resultMap = new LinkedHashMap<>();
return resultMap;
}