38
Web Security Adam C. Champion and Dong Xuan CSE 4471: Information Security

4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

Web Security

Adam C. Champion and Dong XuanCSE 4471: Information Security

Page 2: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

Outline

• Web Basics• Web Threats and Attacks• Countermeasures

Page 3: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

Introduction• Average user spends 16

h/month online (32 h/month in U.S.) [1]– People spend much time

interacting with Web, Web applications (apps)

– Their (lack of) security has major impact

• Interaction via Web browser

• We’ll first review some Web basics

Source: [2], [3]

Page 4: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

The Web• Web page:– Consists of “objects”– Addressed by a URL

• Most Web pages consist of:– Base HTML page, and– Several referenced

objects.• URL has two

components: host name and path name

• User agent for Web is called a browser:– MS Internet Explorer– Netscape

Communicator

• Server for Web is called Web server:– Apache (public

domain)– MS Internet

Information Server

Page 5: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

The Web: the HTTP ProtocolHTTP: HyperText Transfer

Protocol• Web’s application layer protocol• Client/server model

– Client: browser that requests, receives, “displays”Web objects

– Server: Web server sends objects in response to requests

• HTTP 1.0: RFC 1945• HTTP 1.1: RFC 2068

PC runningExplorer

Server running

NCSA Webserver

Mac runningNavigator

HTTP request

HTTP request

HTTP response

HTTP response

Page 6: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

The HTTP Protocol (more)HTTP: TCP transport service:• Client initiates TCP connection

(creates socket) to server, port 80• Server accepts TCP connection

from client• HTTP messages (application-layer

protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server)

• TCP connection closed

HTTP is “stateless”• Server maintains no

information about past client requests

Protocols that maintain “state”are complex!

r Past history (state) must be maintained

r If server/client crashes, their views of “state” may be inconsistent, must be reconciled

aside

Page 7: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

HTTP ExampleSuppose user enters URL http://www.someschool.edu/aDepartment/index.html

1a. HTTP client initiates TCP connection to http server (process) at www.someschool.edu. Port 80 is default for HTTP server.

2. HTTP client sends http request message (containing URL) into TCP connection socket

1b. HTTP server at host www.someschool.edu waiting for TCP connection at port 80. “Accepts” connection, notifies client

3. HTTP server receives request message, forms response messagecontaining requested object (aDepartment/index.html), sends message into socket

time

(contains text, references to 10 JPEG images)

Page 8: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

HTTP Example (Cont.)5. HTTP client receives response

message containing HTML file, displays HTML. Parsing HTML file, finds 10 referenced JPEG objects

6. Steps 1-5 repeated for each of 10 JPEG objects

4. HTTP server closes TCP connection.

time

Page 9: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

Non-Persistent and Persistent Connections

Non-persistent• HTTP/1.0• Server parses request, responds,

and closes TCP connection• 2 RTTs to fetch each object• Each object transfer suffers

from slow start

Persistent• Default for HTTP/1.1• On same TCP connection:

server, parses request, responds, parses new request, …

• Client sends requests for all referenced objects as soon as it receives base HTML.

• Fewer RTTs and less slow start.

But most browsers useparallel TCP connections.

Page 10: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

HTTP Message Format: Request• Two types of HTTP messages: request, response• HTTP request message:

– ASCII (human-readable format)

GET /somedir/page.html HTTP/1.0 User-agent: Mozilla/4.0 Accept: text/html, image/gif,image/jpeg Accept-language:fr

(extra carriage return, line feed)

request line(GET, POST,

HEAD commands)

headerlines

Carriage return, line feed

indicates end of message

Page 11: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

HTTP Request Message: General Format

Page 12: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

HTTP Message Format: Response

HTTP/1.0 200 OK Date: Thu, 06 Aug 1998 12:00:15 GMT Server: Apache/1.3.0 (Unix) Last-Modified: Mon, 22 Jun 1998 …... Content-Length: 6821 Content-Type: text/html

data data data data data ...

status line(protocol

status codestatus phrase)

headerlines

data, e.g., requestedhtml file

Page 13: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

HTTP Response Status Codes

200 OK– request succeeded, requested object later in this message

301 Moved Permanently– requested object moved, new location specified later in this message

(Location:)400 Bad Request

– request message not understood by server404 Not Found

– requested document not found on this server505 HTTP Version Not Supported

In first line in server→client response message.A few sample codes:

Page 14: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

Try HTTP (Client Side) for Yourself1. Telnet to your favorite Web server:

Opens TCP connection to port 80 (default HTTP server port) at www.cse.ohio-state.edu.Anything typed in sent to port 80 at www.cse.ohio-state.edu

telnet www.cse.ohio-state.edu/ 80

2. Type in a GET HTTP request:

GET /~xuan/index.html HTTP/1.0 By typing this in (hit carriagereturn twice), you sendthis minimal (but complete) GET request to HTTP server

3. Look at response message sent by HTTP server!

Page 15: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

HTTP Versions 2, 3

• Max. webpage latency: 250–300 msec (lower is better!)• HTTP 2, 3 designed for security, performance– HTTP 2:

• Supports encryption as “first-class citizen”• More info: I. Gregorik, High Performance Browser Networking,

O’Reilly, 2017; https://hpbn.co/http2/ (Chapter 12)

– HTTP 3:• Uses Google’s QUIC transport protocol (UDP) for lower latency• More info: http://www.chromium.org/quic; A. Langley et al., “The

QUIC Transport Protocol,” Proc. ACM SIGCOMM, 2017; https://www.zdnet.com/article/http-over-quic-to-be-renamed-http3/

15

Page 16: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

Outline

• Web Basics• Web Threats and Attacks– Information Leakage–Misleading Websites–Malicious Code

• Countermeasures

Page 17: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

Information Leakage

• Sensitive information can be leaked via Web:– All files accessible under a Web directory can be

downloaded via GET requests– Example 1: • http://www.website.com/secret.jpg publicly accessible• http://www.website.com/index.html has no link to

secret.jpg• Attacker can still download secret.jpg via GET request!

– Example 2: searching online for “proprietary confidential” information

Page 18: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

Misleading Websites

• Cybersquatters can register domain names similar to (trademarked) company, individual names

• Example: http://www.google.com vs. http://gogle.com vs. …

• Practice is illegal if done “in bad faith”• Arbitration procedures available for name

reassignment (ICANN)

Page 19: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

XSS and CSRF• Cross-site scripting (XSS): inject JavaScript from

external source into insecure websites– Example: input <script type=“text/javascript”><!--evil code--></script>

• Cross-site request forgery (CSRF): force victim browser to send request to external website → performs task on browser’s behalf– Example: force load <img src=“http://www.bigbank.com/transferFunds.php?from=User&to=Attacker”/>

Page 20: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

SQL Injection

• Common vulnerability (~71 attacks/hour [18])• Exploits Web apps that [17, 19]– Poorly validate user input for SQL string literal escape

characters, e.g., '

• Example: [19]– "SELECT * FROM users WHERE name = '" + userName + "';"• If userName is set to ' or '1'='1, the resulting SQL is SELECT * FROM users WHERE name = '' OR '1'='1';

• This evaluates to SELECT * FROM users⇒ displays all users

Page 21: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

Malicious Shellcode• Shellcode is non-self-contained binary executable code

– Distinct from malware that executes on its own– Shellcode can only execute after injection into a running process’s

virtual address space• Most shellcode written in Intel IA-32 assembly language (x86)• When injected into JS code, shellcode executes

– Hijacks browser process– Can totally control target process or system

• Shellcode: attack vector for malicious code execution on target systems (e.g., Conficker worm)– Usually, browser downloads JS code containing shellcode– JS code executes, controls target process/system

Page 22: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

A Toy Shellcode

• Shellcode for exit() system call– Store 0 into register ebx– Store 1 into register eax– Execute instruction int 0x80

• Assembled shellcode injected into JS code

mov ebx, 0mov eax, 1int 0x80

bb 00 00 00 00 b8 01 00 00 00 cd 80

...3caabb00000000b801000000cd80ad46...

Binary payloadinjection

Shellcode assembly

JS code more JS code

Disguised as normal data; injected into target processes’ address spaces; compromises target processes’ security

Page 23: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

Outline

• Web Basics• Web Threats and Attacks• Countermeasures– HTTPS– Blacklist Filtering–Malicious Code Detection

Page 24: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

HTTPS (HTTP Secure)• HTTPS uses cryptography with HTTP [8]– Alice, Bob have public, private keys; public keys

accessible via certificate authority (CA)– Alice encrypts message with Bob’s public key, signs

message with her private key– Bob decrypts message with his private key, verifies

message using Alice’s public key– Once they “know” each other, they can communicate

via symmetric crypto keys• HTTPS provides greater assurance than HTTP

Page 25: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

TLS/SSL• HTTPS uses Transport

Layer Security (TLS), Secure Sockets Layer (SSL), for secure data transport [8]– Data transmitted via client-

server “tunnel”– Much harder to compromise

than HTTP• Problems: [8]

– Relies on CA infrastructure integrity

– Users can make mistakes (blindly click “OK”)

Tunnel

Web Security, Summer Term 2012 3 Secure HyperText Transfer Protocol 13

Source: [8]

Page 26: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

HTTPS Example• User visits website via HTTPS, e.g., https://gmail.com• Browser sends TLS/SSL request, public key, message

authentication code (MAC) to gmail.com; gmail.comdoes likewise– TLS/SSL encrypt entire connection; HTTP layered atop it– Both parties verify each other’s identity, generate

symmetric key for following communications• Browser retrieves public key certificate from gmail.com

signed by certificate authority (Equifax)– Certificate attests to site’s identity– If certificate is self-signed, browser shows warning

• Browser, gmail.com use symmetric key to encrypt/decrypt subsequent communications

Page 27: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

Blacklist Filtering (1)• Misleading websites: Register domain names similar

trademarks, e.g., www.google.com, gogle.com, etc.• XSS: – Validate user input; reject invalid input – Blacklist offending IP addresses

• CSRF: – Use random “token” in web app forms– If token is replayed, reject form (blacklist IP addresses)

• SQL injection:– Validate user input to databases, reject invalid input– Blacklist IP addresses

Page 28: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

Blacklist Filtering (2)

• Helpful browser extensions:– NoScript/NotScripts/… (stop XSS)– AdBlock (can stop malicious scripts in ads)– SSL Everywhere (force HTTPS)– Google Safe Browsing– etc.

Page 29: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

Defending Against Shellcode

• Two main detection approaches:– Content Analysis

• Checks objects’ contents before using them• Decodes content into instruction sequences, checks if malicious

– Hijack Prevention• Focuses on preventing shellcode from being fully executed• Randomly inserts special bytes into objects’ contents, raises

exception if executed• Can be thwarted using several short “connected” shellcodes

Page 30: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

Content Analysis• Two major types of content analysis:– Static Analysis

• Uses signatures, code patterns to check for malicious instructions• Advantage: Fast• Disadvantages: Incomplete; can be thwarted by obfuscation

techniques– Dynamic Analysis

• Detects a malicious instruction sequence by emulating its execution• Advantages: Resistant to obfuscation; more complete than static

analysis• Disadvantage: Slower

• Focus on dynamic analysis (greater completeness)

Page 31: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

Dynamic Analysis• Approaches assume self-contained shellcodes• Analyses’ shellcode emulation:

– Inefficiently uses JS code execution environment information– All memory reads/writes only go to emulated memory system– Detection uses GetPC code

• Current dynamic analysis approaches can be fooled:– Shellcode using JS code execution environment info– Shellcode using target process virtual memory info– Shellcode not using GetPC code

• To detect all malicious shellcodes, we need a better approach

Page 32: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

JSGuard (1)• Our design rationale: [20]– Use dynamic analysis to detect malicious JS objects

• Create a virtual execution environment for detection– Leveraging: (1) target processes’ virtual memory information; (2)

target systems’ context information in detection– NOT a whole-system emulator

– Facilitate multiple-level redundancy reduction• Stack frames: check origins of JS code being interpreted• Native methods: check if native methods to be called originate

from JS interpreter or external components• Objects’ properties

• Assume: JS interpreter’s (native) methods have no memory errors

Page 33: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

JSGuard (2)• It’s hard to fool our method: [20]– Shellcode can use JS code execution environment

information to fool other dynamic analysis approaches• Our design leverages system’s context information

– Shellcode can use target process’s virtual memory information to fool other dynamic analysis approaches• Our design uses target processes’ virtual memory information

– Shellcode can avoid GetPC code to fool other dynamic analysis approaches• Our method does not rely on GetPC code for detection. We

leverage real virtual memory content to decode instructions and emulate their execution

Page 34: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

JSGuard (3)• JSGuard architecture shown in figure below [20]• We mainly check JSString objects for shellcode injection (hard

to inject shellcode in other JS objects)• Architecture runs in client-side application’s address space

(Firefox browser)• JSString objects input to malicious JSString detector, which

scans for shellcode using shellcode analyzer

Source: [20]

Page 35: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

Summary

• Web based on plaintext HTTP protocol (stateless)

• Web security threats include information leakage, misleading websites, and malicious code

• Countermeasures include HTTPS, blacklist filtering mechanisms, and malicious code detection

Page 36: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

References (1)1. Go-Gulf.com, “How People Spend Their Time Online,” 2012,

http://www.mindjumpers.com/blog/wp-content/uploads/2012/05/online-time.jpg2.gif2. P. Irish, http://paulirish.com/lovesyou/new-browser-logos3. Twitter, “Bootstrap,” http://twitter.github.com/bootstrap/4. E. Benoist, “HTTP – Hypertext Transfer Protocol,” 2012, http://benoist.ch/WebSecurity/

slides/http/slidesHTTP.pdf5. Electronic Frontier Foundation, “Panopticlick,” https://panopticlick.eff.org/6. M. Zalewski, The Tangled Web: A Guide to Securing Modern Web apps, No Starch Press,

San Francisco, 2012.7. RFC 2616, https://www.rfc-editor.org/rfc/rfc2616.txt8. E. Benoist, “HTTPS – Secure HTTP,” 2012, http://benoist.ch/WebSecurity/slides/https/

slidesHTTPS.pdf9. E. Benoist, “Cross Site Scripting – XSS,” 2012, http://benoist.ch/WebSecurity/slides/

crossSiteScripting/slidesXSS.pdf10. Wikipedia, “Cross-site scripting,” 2012, https://en.wikipedia.org/wiki/Cross-site_scripting11. Wikipedia, “Same origin policy,” 2012, https://en.wikipedia.org/wiki/Same_origin_policy

Page 37: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

References (2)12. E. Benoist, “Cross Site Request Forgery – CSRF,” 2012, http://benoist.ch/WebSecurity/slides/

csrf/slidesCSRF.pdf13. Wikipedia, “Confused deputy problem,” 2012, https://en.wikipedia.org/wiki/

Confused_deputy_problem14. Wikipedia, “Cross-site Request Forgery,” 2012, https://en.wikipedia.org/wiki/

Cross-site_request_forgery15. T. Wilson, “Hacker Steals Data on 18M Auction Customers in South Korea,” Dark Reading,

26 Feb. 2008, http://www.darkreading.com/security/perimeter-security/211201111/16. J. Grossman, “Hacking Intranet Sites from the Outside,” Black Hat, 2006,

http://www.blackhat.com/presentations/bh-jp-06/BH-JP-06-Grossman.pdf17. E. Benoist, “Injection Flows,” 2012, http://benoist.ch/WebSecurity/slides/injectionFlows/

slidesInjectionFlows.pdf18. Imperva, “SQL Injection: By The Numbers,” 20 Sep. 2011, http://blog.imperva.com/2011/09/

sql-injection-by-the-numbers.html19. Wikipedia, “SQL injection,” 2012, https://en.wikipedia.org/wiki/Sql_injection20. B. Gu, W. Zhang, X. Bai, A. C. Champion, F. Qin, and D. Xuan, “JSGuard: Shellcode

Detection in JavaScript,” Proc. SECURECOMM, 2012.21. Open Web Application Security Project (OWASP), http://owasp.org

Page 38: 4471 web security handoutweb.cse.ohio-state.edu › ... › 4471_web_security_handout.pdf · 2019-07-10 · Malicious Shellcode •Shellcode is non-self-containedbinary executable

References (3)22. G. T. Buehrer, B. W. Weide, and P. A. G. Sivilotti, “Using Parse Tree Validation to Prevent

SQL Injection Attacks,” Proc. FSE/ESEC Int’l. Workshop on Software Engineering and Middleware, 2005.

23. Wikipedia, “HTTP Secure,” https://en.wikipedia.org/wiki/Https