CSRF 공격 aDAY22 참고 cd /home/dvwa/public_html/logs tail -f access.log 192.168.56.101 - - [18/Jan/2025:10:18:55 +0900] "GET /vulnerabilities/csrf/?password_new=password&password_conf=password&Change=Change HTTP/1.1" 200 2307"-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.6167.85 Safari/537.36"
ci3.st.kr 구축 DAY13 참고 [ci3] 구조 1. aplication 2. system http://example.com/index.php/welcome index.php > method(함수) welcome > class/controller application > controllers > Auth.php class Auth extens CI_Controller { public function login()/signup()/mypage()/logout() { $this->load>view('auth/(login/signup/mypage/logout)'); } application > views > auth login.php logout.php mypage.php signup.php ci3.st.kr/index.php/Auth/login ci3.st.kr/index.php/Auth/signup ci3.st.kr/index.php/Auth/mypage ci3.st.kr/index.php/Auth/logout
*기존에 만든 계정들과 차이점은 무엇이며 보안측면에서는 우수한가? 우수했던 부분 1. 프레임워크 디렉토리등은 nikto로 탐지 불가능 2. csrf 막는 토큰 생성 < ?=csrf_field()?> 추가 (csrf막는 토큰 생성) ***대부분의 프레임워크 방식 시스템에서는 post방식일 경우 꼭 추가를 권장함*** [ci4] 구조 1. app 2. public 3. system 4. tests 5. writable *MVC(Model-View-Controller...) *단축 url을 사용하는 추세 반영 설정 1. 계정활성화 ci4.st.kr 구축 2. 호스팅 수정 cd /etc/apache2/sites-available/hosting.conf < VirtualHost *:80> DocumentRoot /home/ci4/public_html/public ServerName ci4.st.kr ServerAdmin ci4@ci4.st.kr Errorlog /home/ci4/public_html/logs/error.log CustomLog /home/ci4/public_html/logs/access.log combined < /VirtualHost> < Directory /var/www/html/> AllowOverride All Require all granted Options None < /Directory> 3. writable 권한 바꾸기 chmod -R 777 writable (권한변경) 4. a2enmod rewrite 5. cd /home/ci4/public_html cp env .env nano .env CI_ENVIRONMENT = development (개발자모드 변경) < ->production (?) 에러 뜨면 이유를 알려줌 => ci4.st.kr 연결됨!
*public만 사용권한 있음 index.php도 public에 숨어있음 app > config > app.php public string $baseURL = "ci4.st.kr/"로 변경 app > config > routes.php (경로지정 파일) $routes->get('/', 'Home::index') $routes->get('/auth/', 'Auth::index') $routes->post('/auth/login', 'Auth::login') #post인 이유? 로그인창에서 버튼을 누르게 하기 위해(db연동 필요) $routes->get('/auth/logout', 'Auth::logout') $routes->get('/auth/mypage', 'Auth::mypage') app > controllers > auth.php 생성 (cp home) 구조짜기 app > views > auth, templates 디렉토리 생성 auth > login.php logout.php mypage.php signup.php templtes > header.php footer.php public > static 디렉토리 생성 bootstrap.bundle.min bootstrap.min.css 추가 header.php에 web2.st.kr의 해더 가져오기 링크 부분 아래처럼 변경 < link rel="stylesheet" href="< ?=base_url('static/bootstrap.min.css'); ?>"> < script src="< ?=base_url('static/bootstrap.bundle.min.js'); ?>">< /script> login.php 바탕화면의 로그인.php 붙여넣고 수정 < div class="container mt-3"> < h2>로그인< /h2> < ?php if (session()->getFlashdata('msg')): ?> < div class="alert alert-danger"> < ?=session()->getFlashdata('msg')?> < /div> < ?php endif; ?> < form action="/auth/login" method="post"> < ?=csrf_field()?> < !-- 쿠기값 안뜸 --> < dis class="mb-3 mt-3"> < label for="id_param">아이디< /label> < input type="text" class="form-control" id="id_param" placeholder="아이디 입력" name="id_param"> < /div> < div class="mb-3"> < label for="pw_param">비밀번호< /label> < input type="password" class="form-control" id="pw_param" placeholder="비밀번호 입력" name="pw_param"> < /div> < div class="form-check mb-3"> < label class="form-check-label"> < input class="form-check-input" type="checkbox" name="remember"> Remember me < /label> < /div> < button type="submit" class="btn btn-primary">Submit< /button> < /form> < /div> < /body> < /html> < form action="/action_page.php"> 대신 < form action="/auth/login" method="post"> 추가 < ?=csrf_field()?> 추가 (csrf막는 토큰 생성) ***대부분의 프레임워크 방식 시스템에서는 post방식일 경우 꼭 추가를 권장함*** < h2>로그인< /h2> 밑에 < ?php if (session()->getFlashdata('msg')): ?> < div class="alert alert-danger"> < ?=session()->getFlashdata('msg')?> < /div> < ?php endif; ?> 추가 Auth.php 수정및 추가 public function login() { helper(['form','url']); $session = session(); $model = new AuthModel(); /* $rules 'id_param'=>?, 'pw_param'=>? ]; if() { } */ $id_param = $this->request->getPost('id_param'); $pw_param = $this->request->getPost('pw_param'); $result = $model->checkUser($id_param, $pw_param); if($result) { #$session-> #$session-> return redirect()->to('/'); } $session->setFlashdata('msg','틀렸어'); return redirect->to*('/auth'); } public function mypage(): string { return view('auth/mypage'); } public function logout(): string { return view('auth/logout'); } }
*db문제 -> models 화면문제 -> views 연결, 작동 -> contollers app > config > database.php 'username' => 'ci4', 'password' => '123456', 'database' => 'ci4', *로그인 입력 페이지 >get방식 submit (로그인_ok?)> 포스트방식 mysql CREATE DATABASE ci4; CREATE USER 'ci4'@'192.168.56.104' IDENTIFIED BY '12345'; GRANT ALL PRIVILEGES ON ci4.* TO 'ci4'@'192.168.56.104'; FLUSH PRIVILEGES; CREATE DATABASE ci4; CREATE USER 'ci4'@'localhost' IDENTIFIED BY '12345'; GRANT ALL PRIVILEGES ON ci4.* TO 'ci4'@'localhost'; FLUSH PRIVILEGES; workbench ci4 연결 테이블추가 CREATE TABLE users ( idx int(6), id_param varchar(15), pw_param varchar(32), last_login TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, failed_login INT(3), PRIMARY KEY (idx) ); admin/123456/2025-01-18 00:00:00/0 --------------------------- #app>controllers>auth 분석(o) #app>views>auth/login 분석(o) #app>models>authmodel 분석 AuthModel.php < ?php namespace App\Models; use CodeIgniter\Model; class AuthModel extends Model { protected $table = 'users'; protected $primaryKey = 'idx'; protected $allowdFields = ['id_param','pw_param']' public function checkUser($id_param, $pw_param) { #$sql = "select * from users where id_param='$id_param' && $pw_param'"; $user = $this->where('id_param',$id_param)->first(); if($user && $pw_param$user['pw_param',$user['pw_param'])){ return True; } return null; } }
AuthModel.php password_verify($pw_param,$user['pw_param']는 적용이 안된다~~ 어떻게 바꿔야 할까? $user && $pw_param==$user['pw_param']
app/ config/ 구성 파일 저장 controllers/ 프로그램 흐름을 결정하는 컨트롤러 database/ 데이터베이스 마이그레이션 및 시드 파일 저장 filters/ 컨트롤러 전후에 실행할 수 있는 필터 클래스 저장 helpers/ 독립형 함수 모음 저장 language/ 다국어 지원을 위한 언어 파일 저장 libraries/ 카테고리에 포함되지 않는 유용한 클래스 모음 models/ 데이터베이스와 함께 작동하는 모델 저장 thirdparty/ 어플리케이션에서 사용할 수 있는 타사 라이브러리 views/ 클라이언트에 표시되는 html로 구성된 뷰