The following video was recorded live at the conference and produced by the Sound of Knowledge Incorporated. Welcome to the annual DEF CON convention. This meeting was held in exciting Las Vegas, Nevada from July 9th through the 11th, 1999. This is videotape number 9, Hacking Oracle 101. Thank you. First off, there's my email address. If anybody wants copies of these slides, just send me an email. First, a usual disclaimer. And then, because of my professional affiliations, my absolutely necessary disclaimer. I'm not saying go out and use this information for any kind of illegal purposes. Okay, what is Oracle? Oracle is a relational database management system. Databases provide a transparent interface between the storage of data and the representation of data. And Oracle is a very widely used database. It's very prevalent in industry. What's the value of attending this presentation? One is that, like I said, Oracle is widely used. If you get some Oracle expertise, you can go out and make some money with it. And you can apply the knowledge learned here for some good things. Oracle uses standard code. It's a standard query language to get data into the database. Here's some Oracle SQL tools. SQL is probably the most widely used. It's basically a shell to do standard query language commands. Forms is an Oracle application. Report writer is a GUI front-end data query tool. SQL menu also is an application front-end for menu applications. SQL loader will load data from system files into the database. SQL net is the TCP IP communications protocol used to communicate in client-server fashion. And SQL DBA is an administration tool. Here's a few other Oracle tools. Basically, these are CASE tools, the first two, to help develop applications. And the last one is a newer reporting utility. Here's current programming languages that can be used to create batch jobs or application code for Oracle applications. Basically, it's each of these. Each of these languages with a compiler that will let you embed SQL commands into that language, into that compiler. This is the way Oracle stores data in tables. Here's a sample table. These are columns. SSL columns. Last name, first name. These are rows within the table, and any single data element within a column, within a row is called a record. If you're on an OS and you want to know if they have Oracle on that OS, here are some ways you can determine if Oracle is present on that system. On Unix, it's Oracle. On PS, list the processes and grep anything with ORA in it. On MVS, under Interactive System Productivity Facility, there should be an Oracle option. On VMS, you list the processes. On NT, there will be an Oracle option under Programs, and it will also be running as a service. Thank you. Thank you. Thank you. In order to access the database, you have to have a few things. You have to have your path set up to where you can access the Oracle executables. You also have to be pointing to the system ID of the database. Oracle databases are named with system IDs, and it's just basically a generic naming standard. You can name it DB01, DB02, DB03. You just have to be pointing to the valid database in order to access it. You need a valid user ID with Connect privileges. In order to identify valid environment variables, you could check the INI files to see what databases have been loaded on that system. In the environment variables, the path and the SID will be in those files. On MVS, it's in sys1.proclib. On VMS, INI files, and NT, INI files. The types of user IDs that exist in an Oracle database. DBA, database administrator, basically can do anything they want. This is the God ID within Oracle. Privileged user is a user that has been granted specific privileges to data elements within the database. An unprivileged user can be a user ID that's been created but has been given no privileges but can access anything that's been granted to public. Within Oracle, some system elements exist. And sometimes data elements are granted to public, which means any user ID can access it. So you don't need specific permissions if it's been granted to public. Oracle uses several different types of authentication options. One is authenticated by the operating system. If you have a valid user ID in the operating system, you can get into the database. Another is a standard user ID and password stored in the database. And two more are X509 certificates and smart cards, which are newer options. With operating system authentication, this is probably the most widely used authentication due to lack of password management within the database. And what happens in this case, is you have a valid operating system user ID, and in the database you have the same ID that has a prefix of OPS$. And that's the default. It can be something different, but that's pretty much 99% of the time that's the prefix. So if you've signed on to the operating system, you type SQL plus to try and get into the SQL shell, and when it prompts you for a user ID, you just put slash and it lets you into the database. So, what does that mean? If you can become a user on the operating system that has a valid database user ID, and you're using OS authentication, you're in the database. No additional authentication required. If you're doing some type of penetration testing or certification and accreditation testing, you should check out some user IDs that are on the OS that look like they're Oracle application users, to see if you can get to that ID and then get to the database. Another way is to look for IDs that are in the DBA group, because if you can get to one of those IDs and get into the database, you're now God of the database. The user ID and password authentication. This is pretty much used for client server environments. The user IDs can be from 1 to 30 characters. It cannot be miles, but it can be a space. Passwords are stored, DES encrypted in the database. And basically when you log in, it will encrypt the password value that you enter and match it up against the stored value in the database. The big problem with this is that the DES key to do this crypto is not well secured. So, if you access that key, you can pretty much crack all the passwords in the database. user id and password authentication every oracle implementation has three default user ids and passwords anytime an oracle database is installed these ids and passwords exist the first one is sys the password is change uninstall the second one is system the password is manager and like i said if you're doing certification and accreditation testing these are things you should try and the third is scott password is tiger and that that's basically an unprivileged user id but it's it's always there but if you're a security person and you're installing or someone's installed a database you should go change these passwords sys is the only id that can start stop or tune the database but system or any other id that has the dba role granted to it can do anything in the database except start stop or tune it the x509 certificate authentication um the newest version of oracle is oracle 8 it's been around for about a year now um they have a separate security server that's an option with the database and with it you can use x509 certificates to authenticate yourself to the security server and then to the database and the smart card is the same thing if you're doing certification and accreditation testing of a database um on most implementations any user in the dba group can run the sql dba utility and type the words connect internal and be logged in as sys and use of the sql dba utility should be locked down on oracle implementations but it's usually not and it won't work on nt because nt handles groups differently than unix and vms and mvs it doesn't recognize group privileges the same way okay once you're in the database um how do you access the data you must have some kind of a database that you can access the data in order to help your organization use the antibiotics in the database oracle can limit specific granted access to the tables or views of the tables within oracle you can mimic access to a to a table to certain data elements within the table through use of views so once you're in the database you have to have these table privileges granted to you to get to the data and table privileges can be given on a table by table basis um lots of tables can be grouped into what's called a row and they're not really?" can be granted to the user and only the owner of the table can grant access to the table or a user id that has been granted access to the table by the owner with grant authority so they can re-grant permissions once they've been granted permissions that's not typically done like i said before the access views can provide granularity of record level access you can limit it just to specific rows or specific columns or specific records within a row within a column and all users employ sql in some way to retrieve to retrieve and present data uh also besides the database data being in the database um it's obviously in the os files and those os files may not always be well protected if you find the os files and they're readable a lot of the data will be gibberish because of the format it's stored in but there will be normal readable clear text data in those os files so it's not always necessary to get into the database to look at the data um oracle subdirectories have names like those listed here and like i said accessing data this way is not going to restrict you to certain rows or columns or records within the database here are some oracle system privileges you must grant connect to any user id that has to log into the database connect as a rule within oracle if you grant the resource role to a user that will allow them to create manage or drop database resources such as tables within their schema, which means under their user ID. And DBA is a role which allows users to do just about anything they want to do within the database. And within Oracle, Oracle 7 and 8 came out with some other granular roles to further limit access to system resources. So you have some granularity where you don't have to make a user a DBA or just a normal user. You can just give them only the privileges they need to do their job. But before Oracle 7, these were pretty much the only system roles that existed. Any and all system privileges. System privileges can be granted by any user with the DBA privilege. So if you want to grant a system privilege to a user, if you're a DBA, you can grant any system privilege. You cannot grant system privileges to a non-DBA with grant authority. Auditing within the database. Auditing in Oracle can be turned globally on or off by modifying the I&I files for the database. This is going to require a restart to actually get the database to start or stop logging. However, DBA can turn on or off auditing within the database by issuing commands and it would not require a database restart for that change to take effect. The DBA can set granular or global auditing parameters and basically I'm going to get into some commands later that specify the different types of auditing that a DBA can do within the database. All audit records are... sent to the SYS.aud$system table. Any DBA can access those audit records not through querying the table itself, but through querying views that have been created to point to that table. The sysaud$table must be backed up to regular tables and cleared periodically. And the reason why... right here. If the CISR dollar table grows to 50,000 records the database basically stops running. And if you audit every successful read of an oracle table you're going to reach that limit pretty fast. Okay, Oracle Password Management. Other than the fact that you have to have a password to access the database, all Oracle versions prior to version 8 have no password management features. What does that mean? that means that a user can establish a password of a space, a run or an A or anything. They can establish passwords that match their names or user IDs. Passwords will never expire and accounts will never be locked within any version of Oracle prior to 8. Most people are still on 7 or lower. Some people have moved to 8, but there's been some instability within version 8 that's kept some people from moving there. Exceptions to that prior slide, if you're trying to connect to the database after three unsuccessful login attempts, the SQL plus session or login session will be terminated. However, you can restart that session thousands and thousands of times. Then that user ID will never be locked. It's just a lockout on invalid passwords within the log on form. These two companies, Moore Systems and Braintree, offer third party password management software for Oracle version 7 and 8. Oracle 8 finally put some password management into the database. Mainly because people are not like me, bitched enough for them to do it. If you're looking in an OS and you want to know if Braintree or More is being used to do password management within an Oracle database version 7 or 8, they have sysos ID's. The Braintree user ID on the OS would be SQLCQR. I don't know what the More user ID is, but I'm sure it can be found on Moore's website. You call them up, ask them whatever, some information about their product. Within Oracle 8, password management parameters can be set by any DBA, and if you list the default profile on the Oracle database, it'll show the password management parameters that exist under Oracle 8, which can be turned on or off, or set to different parameters or levels. Oracle TCP IP sessions. The SQLNET protocol is used to remotely connect to the Oracle database. Multiple database instances will usually run on a single protocol. server and each instance will require its own listener or port. So basically you can have three or four or five database instances running on an operating system and you just have to have separate listeners for the SQL net connection to connect to. Oracle server listeners usually run in this port range, 1,500 to 1,599. In order to encrypt SQL net sessions, there was a product called Secure Network Services. Now it's called Advanced Networking Option and sometimes it's used, sometimes it's not. The crypto strength of ANO is pretty good, but there are some flaws in the key exchange protocol and basically if you want to know what they are, you probably have to do a source code review and sign a non-disclosure agreement like I have and you'll be able to pick out that stuff. And ANO encryption can be mandated or controlled. It can be optional. So the server can say every TCP IP SQL notes session is encrypted or you can encrypt if the client wants to or not. Here are some useful SQL statements. Grant connect to user ID being any user ID. You want a name, identified by password being any password you want to name. That will create a new user within the Oracle database. If you want to change a user's password, you could use that second command. And basically all the information here, I gave this presentation to a guy that had to do some certification testing and he took this presentation and went at this database. He knew nothing about it. He really didn't know anything about Oracle and he was able to get into the database lots of different ways and do lots of different things once he got there. You can grant the DBA role to a user ID if you are a DBA or if you're in the system account or sys account within the database and you can drop user IDs by drop user, user ID, cascade. The cascade is an option. And it will drop all the tables created by a user when you delete the user ID. If you don't use cascade, the user ID goes away but the tables still exist. You can look at all user IDs and passwords in the database by issuing the top command. You have to be a DBA to access any DBA table. And basically that's any table that starts with the name sys.dbasomething. Only DBAs can query those tables. There are also some tables within Oracle that start with the word ALL. Any user ID on the system can query those tables. So any user could look at all the user IDs on the system by selecting user name from all users. That table, all users does not have the password stored in it so you would not get the encrypted passwords. Select ASTRIC from profile default. If you're in Oracle 8 and you want to see what the password management settings are, that's the command to do it. And if you wanted to change the default profile, you could do a command like alter profile default. Invalid logins unlimited. So then there would be no lock. What's that? Do you have to be a DBA to do that? Yes. In order to change that default profile, you do have to be a DBA. But there's plenty of ways to become a DBA. If you grant ALL on any table to a user ID, basically it's going to give you a whole list of permissions on that table, like select, which means read, insert into the table, modify the table, delete records out of the table, and a few others like create indexes on the table and links on the table. You can grant specific privileges. So if you want to just grant read access to a user ID, you could do grant select on the table to the user ID. And that user ID would only be able to do that. It would be able to read that table. And you can revoke everything on the table from the user ID if you want to take a row access on a specific table or object. If you want to create a row, basically it's just create row and row name and drop a row or delete a row, drop row, row name. And if you want to add a bunch of tables, you could do that. If you want to add a bunch of table permissions to a row, you basically grant those table permissions to that row. And then the second to last command, you can grant that row to a user. Prior to version 7, there were no rows. So if it's a security administrator, your job was really hard because you had to grant specific table privileges to every user ID on the system. With Oracle 7 and 8, you can just grant it to a single row and grant that row to every user that needs it. And then the last command is to take a row away from the user ID. The granular auditing options are alluded to here. You can turn on auditing for any successful login by using the top command. You can turn on auditing for any unsuccessful login by using the second command. And you can audit specific privileges. Say, anytime someone updates a table, you can audit just that, updates on default, like any table on the system. If you issue that command, any table that gets updated will cut an audit record. Or you can do it on a specific table. This first option is showing how to do it on a specific table instead of every table by default. You can turn off auditing by just doing no audit all on a table. So any access to that table at all would not be auditing if that statement was issued. And no audit all would turn off all statement auditing. Basically, any SQL statements that are issued would not be audited. And no audit all privileges would turn off auditing for any system privilege that was executed. . . No audit all on default will turn off all default audits. If you want to turn on auditing for a specific user, you do audit session by the user ID. And if you want to turn off auditing for a specific user, you just issue no audit session by that user ID. So if you were doing something in the database and you didn't want to be audited, and you could issue that command, you would not be auditing. And delete asterisk from the sys-i-dial table will delete all audit records. . This first statement, say you're querying a database that has a bunch of credit card numbers. This would show you how to possibly retrieve some of those credit card numbers. Or a database that had some other data. The second statement has a wild card. F name, like, Liz, percent sign. Basically, you can put a percent sign before or after any string. And that will give you any option, like Liz or Lizzy, or anything that came after Liz, basically. If you wanted to see all the tables in the database, you could select owner and table name from sys-dba-tables. If you wanted to list all columns within a table, you would do a describe on that table. And if you want to list audit records, here's one of the audit views of the sys-i-dial table that can be queried to look at all audit records for a specific user. . Here's some of the useful security tables within an Oracle database. The first one stores all users and passwords. All passwords in that table. The second one, any table privileges that have been granted to anyone will be stored in that second one. The third one, any system privileges that have been granted to any user will be stored in the third. Any profiles that have been created and granted to specific users will be in the sys-dba-profile table. Any rows that have been created will be in the dba-rows table. Any row privileges, who they've been granted to, will be in the dba-row-privs. And audit records will be under the view of the dba-audit-trail table. And the sys-i-dollar table is the actual audit table. That kind of went quick, but that's it. If anybody has any questions, now's the time. Yes? I'm a newbie when it comes to Oracle, but I can probably ask you also about JS400. Does Oracle do anything like a rollback file? And if it does, and thinking about OS tax on files, is there any way to take, for instance, a rollback file, or OS-type files, transport them off, and set them up in a clean environment to inspect? Do you think using an Oracle Okay, within Oracle there are rollback segments. So if you're doing a lot of changes within the database and something happens, it crashes, you can roll back to some certain period in time. You want to know if you can offload those rollback segments. Yeah, basically you can structure, you can separate some of those things like the rollback segments on different disks on an OS. So if you have a disk crash on a disk that has part of the database, it's not necessarily going to affect where you have stuff like rollback segments if you have it on a different disk. So you can separate those things. As far as putting them on another OS, I'm pretty sure you can do that. Okay. Yeah, I mean, I'm not a DBA, so those functions are kind of outside of my realm. I do know that if you're issuing a bunch of SQL statements and you're not committing those statements to the database periodically, you'll overflow the rollback segments and the database will grind to a halt. So if you're issuing a thousand create user commands and you're not committing those commands every 50 user IDs or something, you'll overflow the rollback segments and the system will halt. Yes? . If you're using OS authentication and a user ID has already logged into the OS, it doesn't matter what the ID in the database has as a password. If it's set up to use OS authentication, and the ID exists that matches the OS ID, and has an OPS dollar prefix, they'll log in. If you want them to have to log into the database, don't use the OS authentication. They'll log into the OS, but if you create an ID for them in the database, don't prefix it with the OPS dollar. And when they connect, they'll have to supply the user ID and password. . Right. And if you're doing SQLNet, that's not OS authentication because you're in client-server mode. You're not logged into the OS. And the ID can exist just as a regular user ID with a password, or it can be OPS dollar user ID with a password. And you'll have to type OPS dollar user ID on the password if you're coming in over SQLNet. Because you haven't authenticated to the OS. . Yes. . No, I have not. I've seen some of it, you know, some sales pitch stuff. Do you have any specific questions about it? . Yeah, I mean, there's problems with that. Like one of them will use a global user ID to access the database, and it's doing all the IDs and ID mappings at the web server. I personally have a little heartache with that. But I haven't fooled with it much. . Oh, yes. . It's vvandal at exploit.com. The O in exploit is a zero. . Yes. . . . It is encrypted. . Here is an offline tool. . . . An offline tool to list the . . . I mean, basically if you can access the OS data files from the OS, you'll see those encrypted passwords there. . Okay. Yes. Right. Just to start, he's asking if it's possible to start the SQLNet listener on a privileged part, like less than 1023, are you asking? If that port's not being used by another service, yes, you can specify the listener to use one of those privileged ports if it's not being used. Yes. Oh, yeah. I mean, those commands I was issuing, if you want to delete all audit records for a specific ID, you can do that. If you want to delete audit records on a specific table, like anybody that's accessed a specific table, you can do that. Basically, you just delete star from the sysadd dollar table where some condition is met, whatever condition you need to meet. Does that answer it? I mean, okay. Yes. Can you go online and make some backup that you have to do to get a date? Yeah, you can, but typically it's a date-based thing where you offload all the, you know, if you're going to be making audit backups, you probably want to store them by some weekly parameter, a monthly parameter, a daily parameter. So you'd have to have your, your script set up to offload just that week's data and then a script that would delete just that week's data. So, you know, you can code that. So, yes, you can automate it. You could, not in the database itself. I mean, there's nothing to trigger that. You could set up something in like Cron to go check it. And, you know, if you select, count from the table and it'll give you how many records, how many rows are in that, in that CISR dollar table. And based on some output condition of it's greater than whatever, 40,000, then you can, you know, kick off whatever you need to to clear it out. Yeah. Yes. Yes. Yes. I tested any vulnerabilities with the SQLNet protocol. As far as like man in the middle attack and getting the key, a crypto key for the session, yeah. But, I mean, as far as anything else, you know, it's either, it's either encrypted or it's not. As far as connecting to the database with SQLNet, you know, you have to have a valid ID once you get there. I haven't found a way to like exploit that to get in otherwise. Yes. Yes. I don't think so. I don't think anybody can drop a DBA table. But I haven't actually tried that. That's a good little test. Yes. Well, that, that was both things that you mentioned. Right. I didn't apply, I didn't use it. Oh, no. Any, any statements, like if you're inserting data into a table, you're inserting some row into a table and you have insert this row, insert this row, insert this row. You can insert to any table you have access to. Yeah. I mean, basically, if you have access to do some type of command, that's going to alter any kind of data, whether it's creating users or inserting data or deleting data. Whatever you have access to do, if you do too many of them without committing them, you will overflow that row back segment. I mean, what I usually do is do a commit like every 50 and no more than 100 statements. I don't know exactly at which point it breaks. It probably depends on the complexity of the SQL command you're issuing. But I never go like over 100 SQL statements without issuing a commit unless I want to break it. Yes. You mentioned earlier that ESP is vulnerable. Can it be done by verbal or by reflectivity? It's just something that's something that Oracle overlooked. I mean, they do have the ability to DES encrypt the passwords, but they didn't really take good consideration in how they were going to protect that DES key. You know, can they fix that? Yeah. Is it fixed right now? No. How is it affected? How is it protected? Basically, it's not. I mean, and I mean, basically, you know, there's a few ways you can find out. You can fool around with it and find it yourself. You can do a source code review and, you know, sign a non-disclosure statement like I did, which is why I'm not disclosing it right now. And you'll find it. Or you can, like, get me drunk and maybe I'll tell you later. So, yes. Yes. When you give them the last thought that they need, is it that these are going to be really, really, like, a group? Well, usually if you're, you know, using OS authentication, if you're setting up a bunch of application users, they'd normally be part of some application group, but it's not necessary for them to be in a specific group at the OS if you're using. Right, with the exception of if they're in the DBA group and they run the SQL DBA utility. That's the only time it'll actually check what the group is. Yes. I have two questions. The first question is, as far as SQL is, is there a way to lock it in and push that or the web server to open it? But you can only execute the procedures on the local database. You don't want line lines or plus custom. But the second thing is, can you not really do application proxy that will work in SQL? If you only want them to execute stored procedures, you can set up profiles for a user within the database that can limit what they can do. You can basically say they can't issue this command, this command, this command, or any command except this one. So, yeah, you can do some stuff to limit what they can execute over a SQL net connection. The second part of that was application proxy. Oh, most of the proxies, if you're talking about firewall proxies or like generic proxies, they're not really doing any command filtering within the proxy. It's just some proxy to get them through the firewall and handle the SQL net traffic. But to me, a generic proxy is not really a proxy. A proxy is going to limit what you can actually do while you're using that. This guy's saying Sidewinder. I don't know what it limits you. What is it limiting? What is it stopping you from doing? It's a SQL net in my experience, so we'll just get drop and make things like that in the stream. Most of, 90% of the time, it's work, right? But there's a difference between the security and the pay here and this HTTP. It's supposed to be fixed and working for them. Yeah, well, most of the ones I've seen were generic, but... The topic of the proxy is just the generic proxy because they're not really working with anyone on the new net with the SQL net and it's for the new network with the other back ports. Right, well, it does that on NT. Yeah, the SQL net implementation on NT uses like a wide range of ports, which is really effed up, you know, if you're like some kind of security administrator. On Unix, it doesn't do that. The listener listens on this port and this port only. So, yeah, if you want an NT and trying to do SQL net, you could have a situation where you can't use proxies because of the wide range of ports and the proxy is not going to handle that. Yes? You would get that the port is open. If you were port scanning, you know, would you know if the port was being used? You would just get an open port and not anything out of it. I, depending on, you know, what kind of scan you were doing, yes, it is. If you were not going to make your cell net live, would that be just a live scan and connect your list name so it's not protocol self-disk connection? What you probably want to be doing is connecting SQL plus over SQL net to see if you get a user name logged in prompt. Yes? Do you have any possible way to exploit the database listener to get operating system show access? If you're in a SQL net session, if you host out, you host out back to your client. You don't host out to the OS. Right, I mean, it's a way to do some sort of this. Oh, I haven't tried that, so don't know. Yes? Do you have any experience with the Oracle running on the belt that we have been playing in now? And so, you know, how they're doing the user, how they're there? No, I've seen it, but I haven't played with it. Don't know. We'll talk about one more question. One more question? One more questions? Thank you all for coming. Thank