부목을 사용하여 Taint 분석을 수행하는 방법?부목 taint 분석을 수행하는 방법
내 우분투 12.04에 부목을 설치했습니다. 다음 내용을
#include<stdio.h>
#include<string.h>
int main(int argc, char *argv[]) {
char a[10];
strncpy(a,argv[1],10);
printf(a);
return 0;
}
또한 생성 splint.xh 파일 :
int printf (/*@[email protected]*/ char *fmt, ...);
char *fgets (char *s, int n, FILE *stream) /*@ensures tainted [email protected]*/ ;
char *strcat (/*@[email protected]*/ char *s1, char *s2) /*@ensures s1:taintedness = s1:taintedness | s2:taintedness @*/ ;
void strncpy (/*@[email protected]*/ char *s1, char *s2, size_t num) /*@ensures s1:taintedness = s1:taintedness | s2:taintedness @*/ ;
또한 생성 splint.mts은 아래의 내용으로 파일 :
attribute taintedness
context reference char *
oneof untainted, tainted
annotations
tainted reference ==> tainted
untainted reference ==> untainted
transfers
tainted as untainted ==> error "Possibly tainted storage used where untainted required."
merge
tainted + untainted ==> tainted
defaults
reference ==> tainted
literal ==> untainted
null ==> untainted
end
아래 작은 테스트 케이스를 만든
그런 다음 명령을 사용하여 부목 도구를 실행하십시오.
splint -mts splint prg001.c
여기서 prg001.c는 샘플 입력이고 "splint"는 splint.mts 및 splint.xh 파일을 나타냅니다. 모든 파일은 현재 디렉토리에 있습니다.
I받은 출력된다 :
부목 3.1.2 --- 21 2012 팔월
prg001.c (주 기능)에 prg001.c : 6 : 1 : 형식 문자열 파라미터 printf는 컴파일 타임 상수가 아닙니다. a 컴파일시 형식 매개 변수를 알 수 없습니다. 인수를 유형 검사 할 수 없기 때문에 보안 취약점이 발생할 수 있습니다. prg001.c : 3 : 14 : 매개 변수 argc가 사용되지 않음 함수 본문에 함수 매개 변수가 사용되지 않았습니다. 형식 호환성 또는 향후 계획에 인수 이 필요한 경우 인수 선언에/@ unused @ /을 사용하십시오. 출력의 모든 더러운 분석의 힌트가 없습니다
확인 완료--- 2 코드 경고
(사용 경고를 억제하기 위해 -paramuse). 누군가가 부검을 사용하여 오염 분석을 수행하는 방법에 대해 나를 도울 수 있습니까?
감사합니다.
또한 fgets 함수에서 char 배열로 입력하여 인쇄하여 테스트했습니다. 하지만 결과물에 taint에 관한 단서가 없었습니다 – Romaan
문제는 splint.xh 파일에서 발생했습니다. printfxxx로 printf를 변경하면 정상적으로 작동합니다. 표준 정의가 .xh 파일을 덮어 쓰는 것을 의미합니다. 이게 내 문제를 해결했다. – Romaan