
https://dreamhack.io/wargame/challenges/984
SQL INJECTION 취약점을 통해 플래그를 획득하는 로그인 서비스입니다. 로그인 시 계정의 정보가 출력되고, 문제에서 주어진 init.sql 파일의 테이블명과 컬럼명은 실제 이름과 다릅니다.
INSERT INTO users (uid, upw, descr) values ('guest', 'melon', 'For guest');
을 보고, upw에
melon' UNION SELECT * FROM information_schema.tables;--
로 공격 시도했지만, 오류가 났습니다.
(information_schema.tables는 db에 있는 테이블의 정보를 모아둔 테이블입니다.)
오류가 난 이유->컬럼의 갯수가 맞지 않습니다! (users는 4개, fake_table_name은 5개임)
melon' UNION SELECT table_name,0,0,0 FROM information_schema.tables;--
로 upw에 넣을 코드를 수정하였습니다. 우리가 알고싶은건 table_name뿐이기에, 뒤 0,0,0은 users와 컬럼의 갯수를 맞추기 위해 아무 값이나 불러와도 됩니다.
출력된 테이블에서 플래그값이 있을거라 예상되는 onlyflag를 발견했습니다.

->table_name이 onlyflag인걸 알아냈습니다.
컬럼의 이름을 알아내기 위해 information_schema.columns 를 이용해줍니다.
(information_schema.tables는 db에 있는 테이블의 정보를 모아둔 테이블이라면, information_schema.columns는 컬럼의 정보를 모아둔 테이블입니다.)
upw자리에
melon' UNION SELECT column_name,0,0,0 FROM information_schema.columns WHERE table_name = 'onlyflag';--
를 넣어 로그인 해줍니다.
컬럼이 idx sname svalue sflag sclose, 총 5개 있음을 알아냈습니다. 
최종적으로 onlyflag 테이블 정보를 빼내려면 upw자리에
melon' UNION SELECT sname, svalue, sflag, sclose FROM onlyflag;--
으로 로그인 하면 정상적인 플래그가 아닌, 비어있는 값이 나옵니다.

-> 컬럼4개를 불렀는데도 sflag가 안나옵니다. >3번째 자리가 출력이 안되는걸 알 수 있습니다.
melon' UNION SELECT svalue, sflag, sname, sclose FROM onlyflag;--
로 순서 바꿔주어 최종적으로 플래그를 획득합니다.

This challenge involved exploiting a classic SQL Injection vulnerability in a login form.
The upw (password) parameter was directly injected into the SQL query without sanitization, allowing us to craft a malicious UNION SELECT payload.
UNION SELECT with information_schema.tables to discover the real table names, adjusting column counts to avoid errors. onlyflag was identified as the likely target containing the flag. information_schema.columns to enumerate the column names of onlyflag. svalue, sflag, etc.), we built a final payload to select and extract the flag. sflag visible.UNION SELECT, information_schema, and output debugging techniques to extract hidden data.