Software Security Daniel Bosk Department of Information and - - PowerPoint PPT Presentation

software security
SMART_READER_LITE
LIVE PREVIEW

Software Security Daniel Bosk Department of Information and - - PowerPoint PPT Presentation

Introduction Broken Abstractions Memory Management Malware References Software Security Daniel Bosk Department of Information and Communication Systems, Mid Sweden University, SE-851 70 Sundsvall 13th March 2019 Daniel Bosk MIUN IKS


slide-1
SLIDE 1

Introduction Broken Abstractions Memory Management Malware References

Software Security

Daniel Bosk

Department of Information and Communication Systems, Mid Sweden University, SE-851 70 Sundsvall

13th March 2019

Daniel Bosk MIUN IKS Software Security 1

slide-2
SLIDE 2

Introduction Broken Abstractions Memory Management Malware References

1 Introduction

Security and Reliability Changes

2 Broken Abstractions

File System Paths Character Encoding Integer Overflows Data and Code

3 Memory Management

Memory Structure Overruns Type Confusion

4 Malware

Background Malware Types

Daniel Bosk MIUN IKS Software Security 2

slide-3
SLIDE 3

Introduction Broken Abstractions Memory Management Malware References Security and Reliability

As long as our computer is offline, used only by ourselves, and we don’t add any accessories (e.g. USB devices [Sch14]), then we don’t have any problems. Problems start to occur when other users start using our software (in some way), then input to our programs isn’t necessarily what we expect.

Daniel Bosk MIUN IKS Software Security 3

slide-4
SLIDE 4

Introduction Broken Abstractions Memory Management Malware References Security and Reliability

As long as our computer is offline, used only by ourselves, and we don’t add any accessories (e.g. USB devices [Sch14]), then we don’t have any problems. Problems start to occur when other users start using our software (in some way), then input to our programs isn’t necessarily what we expect.

Daniel Bosk MIUN IKS Software Security 3

slide-5
SLIDE 5

Introduction Broken Abstractions Memory Management Malware References Security and Reliability

Software reliability This concerns software quality in the sense of accidental failures, i.e. the assumption that input is benign. Software security This concerns software quality in the sense of intentional failures, i.e. the assumption that input is malign.

Daniel Bosk MIUN IKS Software Security 4

slide-6
SLIDE 6

Introduction Broken Abstractions Memory Management Malware References Security and Reliability

Software reliability This concerns software quality in the sense of accidental failures, i.e. the assumption that input is benign. Software security This concerns software quality in the sense of intentional failures, i.e. the assumption that input is malign.

Daniel Bosk MIUN IKS Software Security 4

slide-7
SLIDE 7

Introduction Broken Abstractions Memory Management Malware References Changes

Change is one of the dangers to security. There are systems which are designed to be secure, and actually are secure, but then . . . upgrades are needed, or not needed but wanted. This might come in the form of updating a component or utilizing the system in an environment it wasn’t designed for.

Daniel Bosk MIUN IKS Software Security 5

slide-8
SLIDE 8

Introduction Broken Abstractions Memory Management Malware References

1 Introduction

Security and Reliability Changes

2 Broken Abstractions

File System Paths Character Encoding Integer Overflows Data and Code

3 Memory Management

Memory Structure Overruns Type Confusion

4 Malware

Background Malware Types

Daniel Bosk MIUN IKS Software Security 6

slide-9
SLIDE 9

Introduction Broken Abstractions Memory Management Malware References File System Paths 1

#!/bin/env python3

2

import sys, os

3 4

JAIL_PATH = os.environ["HOME"]

5 6

def jailed_open(filename):

7

return open(JAIL_PATH + "/" + filename)

8 9

def main(argv):

10

f = jailed_open(argv[1])

11 12

print("\\begin{verbatim}")

13

for line in f.readlines():

14

print(line.strip())

15

print("\\end{verbatim}\n")

16 17

if __name__ == "__main__":

18

main(sys.argv)

Daniel Bosk MIUN IKS Software Security 7

slide-10
SLIDE 10

Introduction Broken Abstractions Memory Management Malware References File System Paths

Example (./jail.py ../../etc/passwd) root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin

Daniel Bosk MIUN IKS Software Security 8

slide-11
SLIDE 11

Introduction Broken Abstractions Memory Management Malware References File System Paths

The Problem: Abstraction of paths We had JAIL_PATH = os.environ["HOME"]. We let filename = "../../etc/passwd". Thus the file we open is JAIL_PATH + "/" + filename which results in /home/dbosk/../../etc/passwd . Hence we actually read /etc/passwd.

Daniel Bosk MIUN IKS Software Security 9

slide-12
SLIDE 12

Introduction Broken Abstractions Memory Management Malware References File System Paths

Fine, we ban the string "../". Then what about "..\%c0\%af.."?

Daniel Bosk MIUN IKS Software Security 10

slide-13
SLIDE 13

Introduction Broken Abstractions Memory Management Malware References Character Encoding

All character representations in the computer comes in the form of different encodings, e.g. UTF-8 encoding. The decoders might be programmed differently, some takes into account the errors in different encoders to compensate – and this can be exploited. Where the encoding and decoding is done can also be exploited.

Daniel Bosk MIUN IKS Software Security 11

slide-14
SLIDE 14

Introduction Broken Abstractions Memory Management Malware References Character Encoding

UTF-8

Daniel Bosk MIUN IKS Software Security 12

slide-15
SLIDE 15

Introduction Broken Abstractions Memory Management Malware References Integer Overflows 1

char buf[128];

2 3

void

4

combine( char *s1, size_t len1, char *s2, size_t len2)

5

{

6

if ( len1 + len2 + 1 <= sizeof(buf) ) {

7

strncpy( buf, s1, len1 );

8

strncat( buf, s2, len2 );

9

}

10

}

Daniel Bosk MIUN IKS Software Security 13

slide-16
SLIDE 16

Introduction Broken Abstractions Memory Management Malware References Integer Overflows

The Problem: Abstraction of integers Let len2 be very long, say 232 − 1, i.e. len2 = 0xffffffff. Now we have

len1 + len2 + 1

(mod 232) = len1 + 232 − 1 + 1 (mod 232) = len1 (mod 232) < sizeof(buf). Thus we pass the test, although we shouldn’t.

Daniel Bosk MIUN IKS Software Security 14

slide-17
SLIDE 17

Introduction Broken Abstractions Memory Management Malware References Integer Overflows

Note This is worse if we use signed integers . . .

Daniel Bosk MIUN IKS Software Security 15

slide-18
SLIDE 18

Introduction Broken Abstractions Memory Management Malware References Data and Code

Example (echo.sh "-E test\ning")

1

#!/bin/sh

2

/bin/echo -e ${1}

test\ning

Daniel Bosk MIUN IKS Software Security 16

slide-19
SLIDE 19

Introduction Broken Abstractions Memory Management Malware References Data and Code

Example (echofix.sh "-E test\ning")

1

#!/bin/sh

2

/bin/echo -e "${1}"

  • E test

ing

Daniel Bosk MIUN IKS Software Security 17

slide-20
SLIDE 20

Introduction Broken Abstractions Memory Management Malware References Data and Code

The login(1) and rlogin(1) composition bug was found in Linux and AIX systems which didn’t check the syntax of the username. The syntax of login(1) is login [-p] [-h host] [[-f] user]. The syntax of rlogin(1) is rlogin [-l user] machine. rlogin(1) connects to the machine and runs login user

machine.

However, the user could be chosen to be “-froot”.

Daniel Bosk MIUN IKS Software Security 18

slide-21
SLIDE 21

Introduction Broken Abstractions Memory Management Malware References Data and Code 1

cat ${1} | mail ${2}

What happens with the address "foo@bar.org | rm -Rf /"?

Daniel Bosk MIUN IKS Software Security 19

slide-22
SLIDE 22

Introduction Broken Abstractions Memory Management Malware References Data and Code 1

$sql = "SELECT * FROM client WHERE name = '$name'"

Insert the name Eve' OR 1=1--. This will get a totally different meaning.

Daniel Bosk MIUN IKS Software Security 20

slide-23
SLIDE 23

Introduction Broken Abstractions Memory Management Malware References Data and Code

Figure: XKCD’s Exploits of a Mom. Image: [XKC].

Daniel Bosk MIUN IKS Software Security 21

slide-24
SLIDE 24

Introduction Broken Abstractions Memory Management Malware References

1 Introduction

Security and Reliability Changes

2 Broken Abstractions

File System Paths Character Encoding Integer Overflows Data and Code

3 Memory Management

Memory Structure Overruns Type Confusion

4 Malware

Background Malware Types

Daniel Bosk MIUN IKS Software Security 22

slide-25
SLIDE 25

Introduction Broken Abstractions Memory Management Malware References Memory Structure Daniel Bosk MIUN IKS Software Security 23

slide-26
SLIDE 26

Introduction Broken Abstractions Memory Management Malware References Overruns

Buffer overruns

Stack overruns Heap overruns

All variables in a program use storage from either the stack or heap.

Daniel Bosk MIUN IKS Software Security 24

slide-27
SLIDE 27

Introduction Broken Abstractions Memory Management Malware References Overruns 1

int

2

login( void )

3

{

4

char correct_password[] = "swordfish";

5

char user_password[16] = {0};

6 7

printf( "user password: ");

8

fscanf( "\%s", user_password );

9 10

if ( !strcmp( correct_password, user_password ) )

11

return 0;

12

return 1;

13

}

Daniel Bosk MIUN IKS Software Security 25

slide-28
SLIDE 28

Introduction Broken Abstractions Memory Management Malware References Type Confusion

There are some problems in object-oriented languages too. Trick the system to point to a different memory location. Thus a write using one type actually modifies something believed to be of another type somewhere else.

Daniel Bosk MIUN IKS Software Security 26

slide-29
SLIDE 29

Introduction Broken Abstractions Memory Management Malware References

1 Introduction

Security and Reliability Changes

2 Broken Abstractions

File System Paths Character Encoding Integer Overflows Data and Code

3 Memory Management

Memory Structure Overruns Type Confusion

4 Malware

Background Malware Types

Daniel Bosk MIUN IKS Software Security 27

slide-30
SLIDE 30

Introduction Broken Abstractions Memory Management Malware References Background

Comes from malicious software and means software with a malicious intent. In the early days they were mostly experiments or pranks. Today they are mostly used for special purposes:

steal personal, financial or business information, cripple competition, etc.

Daniel Bosk MIUN IKS Software Security 28

slide-31
SLIDE 31

Introduction Broken Abstractions Memory Management Malware References Background

There are many types of malware. Their classification depends on the largest threat vector.

Daniel Bosk MIUN IKS Software Security 29

slide-32
SLIDE 32

Introduction Broken Abstractions Memory Management Malware References Malware Types

Computer Virus A form of malware which has self-replicating code. It infects other programs by inserting itself into their program code, and in turn when these programs are run the virus payload is run to replicate even further. Worm A form of malware which replicates itself, not by infection, but by copying itself to different disks, via networks, or even emailing itself automatically to everyone in the user’s contact list. Trojan Horse A form of malware which acts as a legitimate program but has hidden features which are malicious, e.g. a utility program which steals your login credentials in the background or simply acts as a backdoor. Usually used in combination of social engineering.

Daniel Bosk MIUN IKS Software Security 30

slide-33
SLIDE 33

Introduction Broken Abstractions Memory Management Malware References Malware Types

Rootkit A piece of software designed to provide access that would otherwise be restricted. It also keeps well-hidden and is notoriously difficult to detect and

  • remove. Usually this comes from modifying the
  • perating system.

Spyware This software simply tries to gather information about a target without their knowledge. Usually the collected information is sent to a third party. Keylogging falls under this category. Adware This is simply a type of malware that presents advertisements to the user of the infected system. Obviously staying undetected is not an option, so making itself difficult to remove is the strategy of choice.

Daniel Bosk MIUN IKS Software Security 31

slide-34
SLIDE 34

Introduction Broken Abstractions Memory Management Malware References Malware Types

Scareware This is a type of malware that uses social engineering to trick users to buy unwanted software, e.g. fake antivirus software. Ransomware This is a type of malware that restricts the users access to the system. A common technique is to encrypt all the user’s files. Then the user is presented with the option of buying the decryption key for bitcoins. They typically propagate as trojans.

Daniel Bosk MIUN IKS Software Security 32

slide-35
SLIDE 35

Introduction Broken Abstractions Memory Management Malware References Malware Types

[Sch14] David Schneider. “USB Flash Drives Are More Dangerous Than You Think”. In: IEEE Spectrum (Aug. 2014). URL: http://spectrum.ieee.org/tech- talk/computing/embedded-systems/usb-flash- drives-are-more-dangerous-than-you-think. [XKC]

  • XKCD. Exploits of a Mom. URL:

http://xkcd.com/327/.

Daniel Bosk MIUN IKS Software Security 33