리눅스맨

리눅스 find 문자열 검색

Background Image
1,000만원 수익
Overlay Image

리눅스 find 문자열 검색 방법을 정리해보았습니다.

지난번 해킹 이후로 다시 한번 서버에 백도어가 있는것을 확인하고 이부분을 주기적으로 삭제하기 위해서 crontab 에 설정하고 있습니다.

 

.haccess 파일이 각 폴더마다 만들어져있ㄷ군요.

 

<FilesMatch ".*\.(?i:phtml|php|suspected)$">
Order Allow,Deny
Deny from all
</FilesMatch>
<FilesMatch "(^([\.])index.php|^content-index.php|^class-wp-rest-controller-index.php|^backup_index.php|^db-cache.php|^db-safe-mode.php|^class-walker-nav-menu-check-index.php|^webindex.php|^adminindex.php|^wp-type.php|^wp-blog.php|^wp-red.php|^qindex.php|^wp-book.php|^alfindex.php|^oldindex.php|^k.php|^alfindex.php|^session-index.php|^wp-class-smtp-index.php|^wp-old-index.php|^oldindex.php|^plugin-install.php|^wpcss.php|^log.txt|^config.bak.php|^wpconfig.bak.php|^wp-1ogin_bak.php|^1ndex.php|^wp-booking.php|^shell.php|^css.php)$">
Order Allow,Deny
Allow from all
</FilesMatch>

 

특정 패턴으로 haccess 파일이 만들어지면 자동으로 삭제되고 관리자에게 문자가 가도록 만들어볼까합니다.

우선 리눅스에서 파일 속에 문자열을 찾는 방법입니다.

 

find . -type f -exec grep -H 'class-wp-rest-controller-index' {} \;

 

haccess 파일속에 class-wp-rest-controller-index 문자열을 찾을 수 있습니다.

 

 

이렇게 찾기만 하면 안되겠죠?

 

찾았으면 찾은 파일을 몽땅 삭제 하도록 하겠습니다.

명령어 마지막 부분에 -delete 옵션을 넣으면 찾는 동시에 삭제까지 됩니다.

 

find . -type f -exec grep -H 'class-wp-rest-controller-index' {} \; -delete

 

이제 crontab -e 명령어로 주기적으로 아래 문자열이 포함된 파일을 몽땅 자동으로 날리도록 세팅하였습니다.

 

find . -type f -exec grep -H ‘i:phtml|php|suspected’ {} \; -delete

 

 

Background Image
1,000만원 수익
Overlay Image

게시됨

카테고리

,

작성자

태그: