그래, 버퍼 오버 플로우에 대한 연구를하고 있습니다. Java로 변환하려고하는 변수 공격에 취약한 C 프로그램이 있습니다. 아무도 그들이 나를 도울 수 있다고 생각하니? 지금까지 나는 여전히 자바 코드를 컴파일 할 수 없었다.JAVA에서 버퍼 오버플로
C 코드
#include <stdio.h>
#include <string.h>
/*
A routine that checks whether the password is correct or not
Standard library call "gets()" does not check for buffer overflow
*/
int checkPassword(){
char passwordFlag = 'F';
char inputPwd[10];
memset(inputPwd, 0, 10);
gets(inputPwd);
if (!strcmp(inputPwd, "goodpass")){
passwordFlag = 'T';
}
if (passwordFlag == 'T'){
return 1;
}
else{
return 0;
}
}
int main()
{
printf("Please enter a password\n");
if (checkPassword() == 1)
{
printf("Successful\n");
return 0;
}
else{
printf("Access Denied.\n");
return -1;
}
}
자바 코드 자바에 존재하지 않는
import java.io.*;
class Numbers {
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter a password");
if (checkPassword() == 1)
{
System.out.println("Successful");
System.exit(1); //you wouldn't exit here but its not like i'm doing anything important
}
else{
System.out.println("Access Denied.");
System.exit(1);
}
}
public static Integer checkPassword(){
char passwordFlag = 'F';
char inputPwd[10];
memset(inputPwd, 0, 10);
gets(inputPwd);
if (!strcmp(inputPwd, "goodpass")){
passwordFlag = 'T';
}
if (passwordFlag == 'T'){
return 1;
}
else{
return 0;
}
}
}
의 memset 함수를 가져옵니다 및 STRCMP는 정의되지 않습니다 : 버퍼 오버 플로우가 정말 자바에서 다음과 같이 작동하지 않기 때문에
그러나, 나는 그것을 변환하는 방법에 대한 걱정하지 것이다 참조하십시오. – Alanmars
자바 코드에 관한 많은 것들이 있습니다 ... 자바가 아닙니다. –
C 라이브러리 함수 이름을 Java로 사용하지 마십시오. 이러한 작업을 수행하려면 Java 방식을 배워야합니다. – Nayuki