내가 자주 듣는 ASP 업로드 취약점은 접미사 이름을 수정 (이미지 파일 접미사로 수정)하여 일부 트로이 목마 파일을 업로드하고 업로드하는 것입니다.
이 상황에서는 다음 기능을 사용하여 다음을 구별합니다.
코드 사본은 다음과 같습니다.
<%
'*********************************************************************************************************************************************************** 누군가
'CheckFileType 함수는 파일이 이미지 파일인지 확인하는 데 사용됩니다.
'파라미터 파일 이름은 로컬 파일의 경로입니다.
'파일 인 JPEG, GIF, BMP, PNG 사진 인 경우 함수는 TRUE를 반환합니다. 그렇지 않으면 False를 반환합니다.
'*********************************************************************************************************************************************************** 누군가
constadtypebinary = 1
dimjpg (1) : jpg (0) = cbyte (& hff) : jpg (1) = cbyte (& hd8)
DIMBMP (1) : BMP (0) = CBYTE (& H42) : BMP (1) = CBYTE (& H4D)
dimpng (3) : png (0) = cbyte (& h89) : png (1) = cbyte (& h50) : png (2) = cbyte (& h4e) : png (3) = cbyte (& h47).
Dimgif (5) : gif (0) = cbyte (& h47) : gif (1) = cbyte (& h49) : gif (2) = cbyte (& h46) : gif (3) = cbyte (& h39) : gif (4) = cbyte (& h38) : gif (5) = cbyte (& h61).
functioncheckfileType (filename)
onerrorresumenext
CheckFileType = false
Dimfstream, FileExt, Stamp, i
fileExt = mid (filename, instrev (filename, ".")+1)
setfstream = server.createobject ( "adodb.stream")
fstream.open
fstream.type = adtypebinary
fstream.loadfromfilefilename
fstream.position = 0
selectCaseFileExt
"JPG", "JPEG"
Stamp = fstream.read (2)
fori = 0to1
ifacb (midb (Stamp, i+1,1)) = jpg (i) thecheckfiletype = trueelsecheckfiletype = false
다음
"GIF"사례
Stamp = fstream.read (6)
fori = 0to5
ifacb (midb (Stamp, i+1,1)) = gif (i) thecheckfiletype = trueelseckeckfiletype = false
다음
사례 "PNG"
Stamp = fstream.read (4)
fori = 0to3
ifacb (midb (Stamp, i+1,1)) = png (i) thecheckfiletype = trueelsecheckfiletype = false
다음
"BMP"사례
Stamp = fstream.read (2)
fori = 0to1
ifacb (midb (Stamp, i+1,1)) = bmp (i) thecheckfiletype = trueelsecheckfiletype = false
다음
EndSelect
fstream.close
setfsetem = 아무것도
iferr.number <> 0thencheckfiletype = false
최종 기능 장애
%>
그런 다음 적용 할 때
코드 사본은 다음과 같습니다. CheckFileType (Server.Mappath ( "CNBRUCE.JPG"))
또는
CheckFileType ( "f : /web/164/images/cnbruce.jpg")))
따라서이 상황은 이미지 업로드에 사용됩니다. 현재 메소드는 먼저 "의사 이미지"파일의 업로드를 허용 한 다음 위의 사용자 정의 기능을 사용하여 파일이 이미지 사양을 준수하는지 여부를 결정하는 것입니다. 트로이 목장 위장 이미지 파일 인 경우 FSO는 예를 들어 다음과 같습니다.
다음과 같이 코드를 복사하십시오 : file.saveasserver.mappath (filename) '파일 저장
ifnotcheckFileType (server.mappath (filename))