• Aucun résultat trouvé

Sécurité des logiciels

N/A
N/A
Protected

Academic year: 2022

Partager "Sécurité des logiciels"

Copied!
25
0
0

Texte intégral

(1)

1

Sécurité des logiciels

Quelques notions de sécurité système

(2)

2

Permissions

(3)

3

Unix users

uid (User identity)

Integer that represents a user

By convention, 0 is for root gid (Group identity)

Integer that represents a group of users

$ id

uid=16595(sathibau) gid=1111(enseignant) groups=1111(enseignant),1113(runtime),

1203(employee),1027(researcher),1211(teacher), …

$ id aguermou

uid=14925(aguermou) gid=1111(enseignant) groups=1111(enseignant),

1203(employee),1027(researcher),1211(teacher), …

(4)

4

Unix permissions

Permissions : rwx

r : Read (4)

w : Write (2)

x : eXecute (1)

Permission triplet : ugo

u : User

g : Group

o : Other

u+rwx,g+rx,o+rx rwx r-x r-x 755 u+rw,g+r,o+r rw- r-- r-- 644 u+rw,g+r rw- r-- --- 640

$ ls -ldn ~sathibau

drwxr-x--x 16595 1111 /net/cremi/sathibau

(5)

5

Changing permissions

chmod 755 ~/tmp

chmod g+rx,o+rx ~/tmp chmod 700 ~/secret

chmod g-rwx,o-rwx ~/secret

Also, see ACL (Access Control List)

(6)

6

setuid

(Set User ID)

(7)

7

setuid

Programs have their own uid, inherited from uid of parent

sshd(sathibau)

\- bash(sathibau)

\- ls(sathibau)

(8)

8

setuid

Programs have their own uid, inherited from uid of parent, except when they change it

sshd(root)

\- sshd(sathibau)

\- bash(sathibau)

\- ls(sathibau)

(9)

9

setuid

Programs have their own uid, inherited from uid of parent, except when they change it

sshd(root)

(10)

10

setuid

Programs have their own uid, inherited from uid of parent, except when they change it

sshd(root)

\- sshd(root)

(11)

11

setuid

Programs have their own uid, inherited from uid of parent, except when they change it

sshd(root)

\- sshd(root) setuid(16595)

setuid() changes the current uid of the calling process

(12)

12

setuid

Programs have their own uid, inherited from uid of parent, except when they change it

sshd(root)

\- sshd(sathibau)

setuid() changes the current uid of the calling process

(13)

13

setuid

Programs have their own uid, inherited from uid of parent, except when they change it

sshd(root)

\- sshd(sathibau)

\- bash(sathibau)

setuid() changes the current uid of the calling process

(14)

14

setuid

Programs have their own uid, inherited from uid of parent, except when the program is setuid

sshd(root)

\- sshd(sathibau)

\- bash(sathibau)

\- chsh(root)

$ ls -l /bin/chsh

-rwsr-xr-x root root /bin/chsh Yes, this is a terrifying design.

They need to be perfectly sane.

We’ll see various ways not to be perfectly sane.

(15)

15

setuid

real uid (getuid()): the uid that started the program

effective uid (geteuid()) : the uid currently set for the program

saved uid (getresuid()) : an uid saved for later use \- bash(sathibau)

\- at(root)

(16)

16

setuid

real uid (getuid()): the uid that started the program

effective uid (geteuid()) : the uid currently set for the program

saved uid (getresuid()) : an uid saved for later use \- bash(sathibau)

\- at(root) seteuid(getuid())

(17)

17

setuid

real uid (getuid()): the uid that started the program

effective uid (geteuid()) : the uid currently set for the program

saved uid (getresuid()) : an uid saved for later use \- bash(sathibau)

\- at(sathibau)

(18)

18

setuid

real uid (getuid()): the uid that started the program

effective uid (geteuid()) : the uid currently set for the program

saved uid (getresuid()) : an uid saved for later use \- bash(sathibau)

\- at(sathibau)

Can use the saved uid to make effective alternate between the two.

(19)

19

PATH,

LD_LIBRARY_PATH,

LD_PRELOAD

(20)

20

PATH

$ which ls /usr/bin/ls

$ echo $PATH

/usr/local/bin:/usr/bin:/bin Can be used to trick setuid programs…

(21)

21

LD_LIBRARY_PATH

$ ldd /usr/bin/ls […]

libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6

$ mkdir ~/lib

$ cp /lib/x86_64-linux-gnu/libc.so.6 ~/lib/

$ export LD_LIBRARY_PATH=~/lib

$ ldd /usr/bin/ls […]

libc.so.6 => /net/cremi/sathibau/lib/libc.so.6 Can be used to override system library

But cannot be used to trick setuid programs…

« safe » execution startup that ignores LD_LIBRARY_PATH

(22)

22

LD_PRELOAD

$ LD_PRELOAD=~/lib/libm.so ldd /usr/bin/ls […]

/net/cremi/sathibau/lib/libm.so

Can be used to override symbols

But cannot be used to trick setuid programs…

« safe » execution startup that ignores LD_PRELOAD

(23)

23

Races

(24)

24

Races

TOCTOU : Time Of Check to Time Of Use char *file = argv[1];

stat(file, &st);

if (st.st_uid == getuid()) {

// User file, can safely open int fd = open(file, O_RDONLY);

read(…); printf(…);

$ ( while true ; do

ln -sf ~/myfile /tmp/hack

ln -sf /etc/shadow /tmp/hack done ) &

$ while ! /bin/suid-victim /tmp/hack; do : ; done

(25)

25

Races

TOCTOU : Time Of Check to Time Of Use

Atomicity between check and use char *file = argv[1];

int fd = open(file, O_RDONLY);

fstat(fd, &st);

if (st.st_uid == getuid()) {

// User file, can safely read read(…); printf(…);

Références

Documents relatifs

Namely, one has to consider the relative cost of an implicit step versus an explicit step, the availability of parallel com- puting, and the nature of the problem which aects

Effect of various cutting fl uids on feed (Fx), thrust (Fy) and cutting (Fz) forces... 6a) demonstrates the resultant vibration for dull, working and fresh tools under various cutting

In this con fi guration, the energy of the exhaust gas and the wasted energy in the condenser of the steam cycle is recovered in the heat recovery steam generator (HRSG) and

● Local variable (aka automatic variable): a variable whose scope is not getting outside of the function. ● Parameters (aka arguments): Data set by the caller for the

But shell code can lookup the random value ... The game never

There are actually some additional headers Which allow to jump between allocations:. ●

● behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements.

● Putting a stack guard to prevent clash.