Alec Muffett Programming Holes PROGRAMMING GOOFS THAT WILL HOSE - - PowerPoint PPT Presentation

alec muffett programming holes programming goofs that
SMART_READER_LITE
LIVE PREVIEW

Alec Muffett Programming Holes PROGRAMMING GOOFS THAT WILL HOSE - - PowerPoint PPT Presentation

Alec Muffett Programming Holes PROGRAMMING GOOFS THAT WILL HOSE YOUR SYSTEM SECURITY (a purely personal viewpoint) ALEC MUFFETT http://www.users.dircon.co.uk/~alecm/ Alec Muffett Programming Holes Muffetts Observation: "Frequently


slide-1
SLIDE 1

Alec Muffett Programming Holes

slide-2
SLIDE 2

Alec Muffett Programming Holes

PROGRAMMING GOOFS http://www.users.dircon.co.uk/~alecm/ THAT WILL HOSE YOUR SYSTEM SECURITY (a purely personal viewpoint) ALEC MUFFETT

slide-3
SLIDE 3

Alec Muffett Programming Holes

Muffett’s Observation: upgrades/patches, mandated by the least secure machines, due to lack of applications in a network are run on the very criticality of the application..." "Frequently the most important or critical

slide-4
SLIDE 4

Alec Muffett Programming Holes

Statements for discussion: "99.9% of bugs are avoidable" (sacrifice the remaining 0.1% to Goedel) "most of these are due to sloppy programming" "we do not learn the lessons of security, even with hindsight and in the aftermath

  • f really major security incidents..."

"amongst the prime causes of this are commercial O/Ses, legacy apps, and ignorance"

slide-5
SLIDE 5

Alec Muffett Programming Holes

The really irritating thing about computer security: THE SAME PROBLEMS COME UP AGAIN AND AGAIN AND AGAIN AND AGAIN AND AGAIN AND AGAIN AND AGAIN

slide-6
SLIDE 6

Alec Muffett Programming Holes

that were used in the 70s, 80s and early 90s are still in use today WHY? The same attacks on networked hosts in the same way as older ones (smtp, ftp) to attack new protocols (gopher, http, ???) and moreover get conceptually re-used

slide-7
SLIDE 7

Alec Muffett Programming Holes

Because:

  • programmers are ignorant when leaving college
  • companies can sell widgets better than security

to the marketplace

  • legacy apps hamper us

(try to convince a vendor to drop sendmail)

  • legislation ties up technologies that can help

(eg: US crypto export) ...AND...

slide-8
SLIDE 8

Alec Muffett Programming Holes

(#pragma personal_cynicism 1) I strongly suspect that nobody really cares*

(*except for the people who have to clear up the mess)

slide-9
SLIDE 9

Alec Muffett Programming Holes

  • viruses (not dealt with by me)

So what are the problems which keep returning?

  • stack overwriting
  • trusting insanitary data
  • authentication spoofing (direct or indirect)
  • OVERPOWERFUL SOFTWARE RUNNING

WITH EXCESS PRIVILEGE ...and poor encryption session key generation not covered in this presentation 1st rev.

slide-10
SLIDE 10

Alec Muffett Programming Holes

Viruses

  • not really my forte
  • possibly the one form of security bug that

is more "social" than "erroneous" in nature

  • like life: so long as there is exchange of data

there will be the possibility that something nasty is piggybacking a ride, inside

slide-11
SLIDE 11

Alec Muffett Programming Holes

Stack Overruns

  • blame squarely on the head of the programmer
  • can cause:
  • denial of service
  • system crash (at protocol level)
  • hacker infestation
slide-12
SLIDE 12

Alec Muffett Programming Holes

Stack Overruns

  • common causes:
  • gets()
  • sprintf()
  • strcat()
  • strcpy()
  • insanitary calls to read()

(Morris Worm) ...into small/undersized memory buffers

slide-13
SLIDE 13

Alec Muffett Programming Holes

Stack Overruns after

stack growth buffer for read() viral code padding return address for routine landing pad of NOPs

before Diagram

slide-14
SLIDE 14

Alec Muffett Programming Holes

Stack Overflows

  • require certain creative bent to programming
  • viral payload usually hand-tooled

assembler code

  • circumstances may dictate that payload

contains no NLs, CRs, NULs, etc... can lead to very creative solutions

  • ...but any moron can execute one that

is packaged up adequately.

slide-15
SLIDE 15

Alec Muffett Programming Holes

Stack Overflows

  • instances:

Morris Worm: unbounded gets() on socket Sendmail: syslog() routine called strcat()

  • n unbounded data read from socket

Ping: NIS+ host resolver library did sprintf()

  • n argv[1] from command line; instant

SUID hack, no network involved. (nb: made more subtle as required DLLs)

slide-16
SLIDE 16

Alec Muffett Programming Holes

Stack Overflows

we will be looking at today

  • f the major holes that

Probably the most straightforward

slide-17
SLIDE 17

Alec Muffett Programming Holes

Insanitary Data

  • Far more subtle class of bugs
  • generally due to meddling/trusting

things that are beyond your control in the first case...

  • so what *is* under your control?
slide-18
SLIDE 18

Alec Muffett Programming Holes

Under your control?

  • files/filestore?
  • executable code?
  • input streams?
  • environment variables?

A good question, nearly metaphysical:

slide-19
SLIDE 19

Alec Muffett Programming Holes

Files under your control? Maybe, but watch out for:

  • user-provided filenames

direct input or thru env vars (PATH, termcap/terminfo, "at")

  • fixed filenames

directory perms, time races in code ("ps", "mail", ...)

  • filestore perms holding config files
  • r parent directories thereof.

("chmod 777 /", GID of "/etc")

slide-20
SLIDE 20

Alec Muffett Programming Holes

Environment under your control? No!

  • Do not expect contents of an env var

to be sane to child processes

  • Remember that env vars will propagate
  • Be suspicious of your ability to unset

a variable before forking a child PATH=/bin:/usr/bin:... IFS=/ IFS=/ ... (multiple instance)

slide-21
SLIDE 21

Alec Muffett Programming Holes

Environment under your control? Only sane way to approach env vars: 1) do not trust anything 2) do not propagate anything that you did not create "everything is forbidden except that which is explicitly permitted"

slide-22
SLIDE 22

Alec Muffett Programming Holes

Input under your control? No!

  • Data servers that are subvertable

(DNS, NIS, NFS, Kerberos)

  • old days: TIOCSTI
  • new days: TCP segment injection/spoof
  • inbound spams (see further down)

"who knows what’s coming down the pipe next?"

slide-23
SLIDE 23

Alec Muffett Programming Holes

Cinderella Attack

  • forge (eg:) poorly-authenticated NTP packets.
  • use this method to wind the clock on the target

host forward to yr 2000-odd

  • software licenses for security software
  • n target machine expire
  • firewall bastion host turns into pumpkin
  • network turns into pumpkin pie.
slide-24
SLIDE 24

Alec Muffett Programming Holes

Code under your control? Alas, probably not.

  • stack overflows/buffer spams
  • new dynamism:
  • shared libraries

(LD_PRELOAD, LC_COLLATE, runpath, LD_LIBRARY_PATH, ...)

  • ever since we gave users dl_open()
  • r similar...
slide-25
SLIDE 25

Alec Muffett Programming Holes

(and yes, your code really *does* matter, it *is* important to know this)

ANYTHING TRUST DON’T

slide-26
SLIDE 26
  • one of the great, perpetual mistakes
  • totally obvious when it is explained, but

re-occurs a lot; either programmers forget that the problem exists, or become blithe in their trust of some other service which leaves them open to subversion.

Alec Muffett Programming Holes

Inbound Record Delimiters

slide-27
SLIDE 27

Alec Muffett Programming Holes

Inbound record delimiters bug, 1970s IFS variable; field separators define notion

  • f "whitespace", in a shellscript...

IFS=/ ; /bin/ls

  • > "bin" "ls"

so, create /tmp/bin that does something nasty, and: suidscriptname # calls /bin/ls, invokes "/tmp/bin" export IFS=/ export PATH=/tmp:$PATH ...works for any char, eg: "IFS=n" -> "/bi" "/ls"

slide-28
SLIDE 28

Alec Muffett Programming Holes

Inbound record delimiters bug, 1980s DNS reverse lookup hostname set to: \nR"|/bin/sed -e ’1,/^$/d’|/bin/sh"\nHxx: Text interpolates into Sendmail’s control file: HReceived-from: HOSTNAME.site.domain becomes: HReceived-from: R"|/bin/sed -e ’1./^$/d’|/bin/sh" Hxx: .site.domain ...makes bogus recipient record in config, due to lack of checking for newlines in input.

slide-29
SLIDE 29

Alec Muffett Programming Holes

Viral input bug, 1980s @ whois ‘/bin/sh < /dev/tty >/dev/tty 2>&1‘ ...escapes from captive environment.

  • Log into NIC to do "whois" query...
slide-30
SLIDE 30

Alec Muffett Programming Holes

Viral input bug, 1990s ...worse still... http://site/cgi-bin/foo?%60rm+%2Drf+%2F%60 (‘rm -rf /‘ gets eval’ed by poor CGI script) http://site/cgi-bin/perl?...

slide-31
SLIDE 31

Alec Muffett Programming Holes

Authentication Spoofing

  • What does this mean?
  • meddling with an established

communications channel

  • forging credentials to lie about

who you are

  • cheating an authentication process

Broad definition:

slide-32
SLIDE 32

Alec Muffett Programming Holes

Authentication Spoofing Examples:

  • sniffing/guessing reusable passwords
  • replaying authentication cookies

b64encode("username:password") eg: HTML document passwords ==

  • pre-empting challenge/response schemes

eg: hijacking S/Key sessions (aka: "beat the clock")

  • TCP stream hijacking or resetting

thru forged addresses or sequence nos

slide-33
SLIDE 33

Alec Muffett Programming Holes

TCP/IP IS NOT FIT FOR USE AS AN AUTHENTICATOR

slide-34
SLIDE 34

Alec Muffett Programming Holes

SO WHY DO PEOPLE PERSIST IN USING IT AS IF IT WERE?

slide-35
SLIDE 35

Alec Muffett Programming Holes

8-)

By now, you should be able to tell me.

slide-36
SLIDE 36

Alec Muffett Programming Holes

Spoofing Example

  • How many people know that "#"
  • Tweak DNS:

#.foo.ac.uk 28800 CNAME host.foo.ac.uk. is not a legal character in a .rhosts file? $ ping # host.foo.ac.uk is alive

  • Go one step further, set "#" as reverse

A-record, and log into any host with a bad .rhosts file...

slide-37
SLIDE 37

Alec Muffett Programming Holes

Spoofing Examples ...but that’s HARD compared to just plain lying.

  • "+" in hosts.equiv, "my name is ’root’... honest"
  • forged "admind" requests from ‘‘localhost’’
  • source routed NFS traffic to implement a VPN
  • forged TCP RSTs to disconnect sessions
  • SYN flooding probably fits this category, too
slide-38
SLIDE 38

Alec Muffett Programming Holes

Excess Privilege

  • Problem cuts both ways:
  • not only use of root permissions for

programs that do not require them...

  • ...but also excessive promiscuity of

data that shouldn’t really be public

  • The BANE of our LIVES
slide-39
SLIDE 39

Alec Muffett Programming Holes

Excess Privilege "sendmail" *THE EXAMPLE* Why run as root?

  • "chown" mailboxes to users? Use groups.
  • protect intermediate files? Unix fileperms.
  • odds and sods? Use SUID modules.
  • TCP port 25 access? Use inetd/fd-passing

What is there about a mail daemon that requires root?

slide-40
SLIDE 40

Alec Muffett Programming Holes

Excess Privilege

  • Encrypted ciphertexts

(how many years before shadow passwords gained common acceptance?) Data users don’t need to see, and data users don’t need to be able to modify.

  • syslog data, etc...
  • world writable tty’s, /dev/console, etc...
  • lots of stupid little things, but...
slide-41
SLIDE 41

Alec Muffett Programming Holes

SECURITY IS HOLISTIC

slide-42
SLIDE 42

Alec Muffett Programming Holes

Irritations of excess privilege:

  • perms on "/etc", rwxrwxr-x, uid=root gid=bin

therefore anyone who can get "bin" can get root.

  • ownership on older /var/spool dirs =uucp

therefore anyone who can get "uucp" can get root (eg: forge a sendmail queuefile)

  • ...and so forth.
slide-43
SLIDE 43

Alec Muffett Programming Holes

Irritations of excess privilege

  • Attitude amongst O/S designers often is:

"files executed by root may be owned by anyone at all..."

  • Attitude should be:

"As much as possible should be root-owned but almost nothing should be root-executed since this automatically limits damage..."

slide-44
SLIDE 44

Alec Muffett Programming Holes

The principle of least privilege: Design your software such that it runs without requiring privileges that are unavailable to normal users. Try not to f*ck up.

slide-45
SLIDE 45

Alec Muffett Programming Holes