실습> 윈도우에서 만든 코드를 리눅스에서 실행하기
1. 윈도우에서 코드 생성
메모장에서 hello.sh 로 저장한다.
-- hello.sh --
#!/bin/sh
echo "Hello bash!"
-- hello.sh --
2. 리눅스에서 코드 실행
hello.sh 파일을 실행권한으로 변경한다.
Attacker# chmod 755 hello.sh
Attacker# cat hello.sh
#!/bin/sh
echo "Hello bash!"
hello.sh 파일을 실행하면 아래처럼 에러가 발생한다.
이유는 윈도우의 엔터와 리눅스의 엔터가 다르기 때문이다.
윈도우의 엔터 : \r\n
리눅스의 엔터 : \n
Attacker# ./hello.sh
-bash: ./hello.sh: /bin/sh^M: bad interpreter: No such file or directory
od 명령어를 이용해서 엔터를 확인한다.
Attacker# od -c hello.sh
0000000 # ! / b i n / s h \r \n \r \n e c h
0000020 o " H e l l o b a s h ! "
0000037
3. 파일 포맷 변경
윈도우의 파일포맷에서 리눅스의 파일포맷으로 변경한다.
ex모드에서 파일 포맷을 변경한다.
:set ff <-- 현재 파일 포맷 형식을 확인한다.
:set ff=unix <-- 파일 포맷을 unix로 변경한다.
:wq
Attacker# vi hello.sh
#!/bin/sh
echo "Hello bash!"
od 명령어를 이용해서 엔터를 확인한다.
\r\n -> \n으로 변경된 것을 확인할 수 있다.
Attacker# od -c hello.sh
0000000 # ! / b i n / s h \n \n e c h o
0000020 " H e l l o b a s h ! " \n
0000036
파일을 실행하면 잘 실행된다.
Attacker# ./hello.sh
Hello bash!
'Linux > 모의해킹' 카테고리의 다른 글
| 아드레날린 프로그램 취약점을 이용한 Reverse Shell 연결하기 (0) | 2022.01.04 |
|---|---|
| Wireshark 공격하기 (0) | 2022.01.04 |
| PoC 란?? (0) | 2022.01.04 |
| 계산기 쉘 코드 생성 후 Windows XP 공격 (0) | 2022.01.04 |
| Wireshark 취약점 migrate 를 이용한 프로세스를 갈아타서 공격 (0) | 2022.01.04 |