| 1 | BIND TRANSFER SECURITY |
|---|
| 2 | ---------------------- |
|---|
| 3 | |
|---|
| 4 | We're going to limit zone transfer of your zones so that only |
|---|
| 5 | your secondary/slave nameservers are allowed to request copies |
|---|
| 6 | of the zones. |
|---|
| 7 | |
|---|
| 8 | Note: if the instructor group (for example, group 0) is providing slave |
|---|
| 9 | (secondary) service for your domain, then the "partner" referred below |
|---|
| 10 | is the instructor responsible for group 0. |
|---|
| 11 | |
|---|
| 12 | ACL based security |
|---|
| 13 | ------------------ |
|---|
| 14 | |
|---|
| 15 | To start with, we'll enable IP based ACLs -- on the AUTH1 host: |
|---|
| 16 | |
|---|
| 17 | 1. Start by editing /etc/namedb/named.conf, and in the "options" section, |
|---|
| 18 | let's define who is allowed to transfer your zone. |
|---|
| 19 | |
|---|
| 20 | allow-transfer { 127.0.0.1; ::1; YOUR_OWN_IP; myslaves; }; |
|---|
| 21 | |
|---|
| 22 | ... replace "YOUR_OWN_IP" with the IP of your machine :) |
|---|
| 23 | |
|---|
| 24 | Now we need to define the ACL "myslaves". To do so, AFTER the options |
|---|
| 25 | section (find the '};' symbol at the end of the section), add something |
|---|
| 26 | similar to this: |
|---|
| 27 | |
|---|
| 28 | (If the slave for your "MYTLD" domain is auth1.grp25, for example) |
|---|
| 29 | |
|---|
| 30 | acl myslaves { 10.20.25.1; 10.20.X.2; }; // ACL with IP of Group25 master |
|---|
| 31 | |
|---|
| 32 | This means "myslaves is an ACL consisting of the IP 10.20.25.1, |
|---|
| 33 | and your NSD secondary 10.20.25.2. |
|---|
| 34 | |
|---|
| 35 | NOTE: remember to enter the correct values! You must write the IP |
|---|
| 36 | of the machine who is your secondary in the class - remember ! |
|---|
| 37 | |
|---|
| 38 | 2. Restart named |
|---|
| 39 | |
|---|
| 40 | $ sudo service named restart |
|---|
| 41 | |
|---|
| 42 | 3. Make sure that you didn't break the zone transfer, by asking your |
|---|
| 43 | slave partner to run a zone transfer against YOUR machine. |
|---|
| 44 | |
|---|
| 45 | From their server: |
|---|
| 46 | |
|---|
| 47 | $ dig @auth1.grpX.dns.nsrc.org MYTLD axfr |
|---|
| 48 | |
|---|
| 49 | Make sure that it still works. |
|---|
| 50 | |
|---|
| 51 | 4. Now try and ask someone else in the class whose server is NOT in the |
|---|
| 52 | ACL to try the same axfr command as above. |
|---|
| 53 | |
|---|
| 54 | Q: Do they succeed ? |
|---|
| 55 | |
|---|
| 56 | Q: What do you see in the logs in /etc/namedb/log/general ? |
|---|
| 57 | What do you see in the logs in /etc/namedb/log/transfers ? |
|---|
| 58 | |
|---|
| 59 | TSIG KEY based security |
|---|
| 60 | ----------------------- |
|---|
| 61 | |
|---|
| 62 | Instead of using IP addresses, we'll now be using cryptographic keys |
|---|
| 63 | to authenticate zone transfer -- this uses TSIG, a mechanism by which |
|---|
| 64 | the communication between the master and slave server will be authenticated |
|---|
| 65 | using this key. |
|---|
| 66 | |
|---|
| 67 | 1. Run: |
|---|
| 68 | |
|---|
| 69 | $ cd /tmp/ |
|---|
| 70 | $ sudo dnssec-keygen -a HMAC-MD5 -b 128 -n HOST mydomain.key |
|---|
| 71 | |
|---|
| 72 | You will see something similar to this: |
|---|
| 73 | |
|---|
| 74 | Kmydomain.key.+157+32373 (the last number will change) |
|---|
| 75 | |
|---|
| 76 | Two files have been created: |
|---|
| 77 | |
|---|
| 78 | $ ls -l K* |
|---|
| 79 | |
|---|
| 80 | Kmydomain.key.+157+32373.key |
|---|
| 81 | Kmydomain.key.+157+32373.private |
|---|
| 82 | |
|---|
| 83 | 2. View the contents of the private key |
|---|
| 84 | |
|---|
| 85 | $ cat Kmydomain.key.+157+32373.private |
|---|
| 86 | |
|---|
| 87 | You will see something similar to: |
|---|
| 88 | |
|---|
| 89 | Private-key-format: v1.2 |
|---|
| 90 | Algorithm: 157 (HMAC_MD5) |
|---|
| 91 | Key: tHTRSKKrmyGmPnzNCf2IRA== |
|---|
| 92 | Bits: AAA= |
|---|
| 93 | |
|---|
| 94 | ... the "Key:" is the important bit here, so copy |
|---|
| 95 | "tHTRSKKrmyGmPnzNCf2IRA==", but of course not the one above, the one |
|---|
| 96 | in YOUR file :) |
|---|
| 97 | |
|---|
| 98 | We will use this in the next steps. |
|---|
| 99 | |
|---|
| 100 | 3. Modify your named.conf |
|---|
| 101 | |
|---|
| 102 | $ cd /etc/namedb/ |
|---|
| 103 | |
|---|
| 104 | Edit the file, and change the allow-transfer statement, so that it looks |
|---|
| 105 | like this: |
|---|
| 106 | |
|---|
| 107 | options { |
|---|
| 108 | ... |
|---|
| 109 | allow-transfer { 127.0.0.1; ::1; }; // myslaves is removed! |
|---|
| 110 | ... |
|---|
| 111 | }; |
|---|
| 112 | |
|---|
| 113 | Note: We have removed "myslaves" |
|---|
| 114 | |
|---|
| 115 | Now, after the options (or at the bottom of the file), add a new |
|---|
| 116 | declaration for the key |
|---|
| 117 | |
|---|
| 118 | key "mydomain-key" { |
|---|
| 119 | algorithm hmac-md5; |
|---|
| 120 | secret "tHTRSKKrmyGmPnzNCf2IRA=="; // Your REAL key goes here! |
|---|
| 121 | |
|---|
| 122 | }; |
|---|
| 123 | |
|---|
| 124 | Change the definition for your zone: |
|---|
| 125 | |
|---|
| 126 | zone "MYTLD" { |
|---|
| 127 | type master; |
|---|
| 128 | file "/etc/namedb/master/mytld"; |
|---|
| 129 | |
|---|
| 130 | allow-transfer { key mydomain-key; }; // <-- Add this! |
|---|
| 131 | }; |
|---|
| 132 | |
|---|
| 133 | As you can see above, we've added an "allow-transfer" statement |
|---|
| 134 | allowing transfer of the zone for holders of the "mydomain-key". |
|---|
| 135 | |
|---|
| 136 | Note: the allow-transfer is now placed INSIDE the zone definition, |
|---|
| 137 | and not globally inside the options section -- BIND can control zone |
|---|
| 138 | transfer either globally, or by zone. We could have chosen to allow |
|---|
| 139 | transfers GLOBALLY (for all zones), by leaving the allow-transfer |
|---|
| 140 | statement in the main "options" section. |
|---|
| 141 | |
|---|
| 142 | 4. Restart named |
|---|
| 143 | |
|---|
| 144 | $ sudo service named restart |
|---|
| 145 | |
|---|
| 146 | 5. Try and make a zone transfer from ANOTER machine -- ask your neighbors to do: |
|---|
| 147 | |
|---|
| 148 | $ dig @10.20.XX.1 MYTLD axfr |
|---|
| 149 | |
|---|
| 150 | Look at /etc/namedb/log/general and /etc/namedb/log/transfers |
|---|
| 151 | |
|---|
| 152 | Q: What do you notice ? |
|---|
| 153 | |
|---|
| 154 | 6. Then, ask them to try again with the key: |
|---|
| 155 | |
|---|
| 156 | $ dig @10.20.XX.1 axfr mydomain -y mydomain-key:tHTRSKKrmyGmPnzNCf2IRA== |
|---|
| 157 | |
|---|
| 158 | Q: what happens now ? |
|---|
| 159 | |
|---|
| 160 | Check the logs again, especially /etc/namedb/log/transfers |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | 7. On your partner's SLAVE host (your secondary - again, this may be |
|---|
| 164 | the instructor if they are providing secondary service for your |
|---|
| 165 | domain). |
|---|
| 166 | |
|---|
| 167 | Start by asking your partner to delete their copy of your zone: |
|---|
| 168 | |
|---|
| 169 | - Have them remove the zone from /etc/namedb/slave/MYTLD -- |
|---|
| 170 | remember, this is on the machine of your SLAVE partner: |
|---|
| 171 | |
|---|
| 172 | $ sudo rm /etc/namedb/slave/MYTLD |
|---|
| 173 | |
|---|
| 174 | - Ask them to restart named |
|---|
| 175 | |
|---|
| 176 | $ sudo service named restart |
|---|
| 177 | |
|---|
| 178 | Check with them that the zone is gone AND that their server wasn't |
|---|
| 179 | able to reload it. |
|---|
| 180 | |
|---|
| 181 | Q: What do you see in the MASTER (auth1) logs (transfers and general) ? |
|---|
| 182 | |
|---|
| 183 | Q: What do you see in the SLAVE logs (transfers and general) ? |
|---|
| 184 | |
|---|
| 185 | 8. Still on the SLAVE (if the instructor is providing secondary service, |
|---|
| 186 | they will perform this part) |
|---|
| 187 | |
|---|
| 188 | Find the statement for the zone: |
|---|
| 189 | |
|---|
| 190 | zone "MYTLD" { |
|---|
| 191 | type slave; |
|---|
| 192 | masters { 10.20.XX.1; }; |
|---|
| 193 | file "slave/mydomain.dns"; |
|---|
| 194 | }; |
|---|
| 195 | |
|---|
| 196 | ... and add the key, and a statement to tell which key to use |
|---|
| 197 | when talking to "10.20.XX.1" (the master): |
|---|
| 198 | |
|---|
| 199 | key mydomain-key { |
|---|
| 200 | algorithm hmac-md5; |
|---|
| 201 | secret "tHTRSKKrmyGmPnzNCf2IRA=="; |
|---|
| 202 | }; |
|---|
| 203 | server 10.20.XX.1 { // here you put the IP of YOUR master |
|---|
| 204 | keys { mydomain-key; }; |
|---|
| 205 | }; |
|---|
| 206 | |
|---|
| 207 | 9. Restart named |
|---|
| 208 | |
|---|
| 209 | $ sudo service named restart |
|---|
| 210 | |
|---|
| 211 | On the SLAVE server: |
|---|
| 212 | |
|---|
| 213 | Q: Is the zone "MYTLD" back in the slave/ directory ? |
|---|
| 214 | |
|---|
| 215 | Q: What do you see in the MASTER (auth1) logs (transfers and general) ? |
|---|
| 216 | |
|---|
| 217 | Q: What do you see in the SLAVE logs (transfers and general) ? |
|---|
| 218 | |
|---|
| 219 | Can you see a general benefit from using keys instead of IP ACLs ? |
|---|
| 220 | |
|---|
| 221 | Optional section if you are running a secondary yourself: |
|---|
| 222 | |
|---|
| 223 | 10. Now, do the same for your NSD "auth2" server |
|---|
| 224 | |
|---|
| 225 | ... since you have disabled IP ACLs, your AUTH NSD server is not |
|---|
| 226 | able to get the zone! |
|---|
| 227 | |
|---|
| 228 | Read the NSD manual page (man nsd.conf) if you are in doubt about |
|---|
| 229 | how to specify the key format in NSD for zone transfers. Update |
|---|
| 230 | update the "zone:" definition for MYTLD, so that it now uses |
|---|
| 231 | a KEY instead of NOKEY to transfer the zone from your MASTER (auth1). |
|---|
| 232 | |
|---|
| 233 | After, you will need to run "nsdc restart". Does the zone get |
|---|
| 234 | transferred ? Remember to check the logs on the MASTER (auth1) as |
|---|
| 235 | well! |
|---|
| 236 | |
|---|
| 237 | Optional section if you are using Swatch to monitor the logs: |
|---|
| 238 | |
|---|
| 239 | 11. If you set up Swatch in a previous exercise, make it complain if it |
|---|
| 240 | sees a forbidden zone transfer: |
|---|
| 241 | |
|---|
| 242 | Edit /usr/local/etc/swatch.conf, and add a new section -- remember |
|---|
| 243 | to use TAB for the space at the beginning of the lines: |
|---|
| 244 | |
|---|
| 245 | - - - - - - - - - - - - - - - cut below - - - - - - - - - - - - - - |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | watchfor /client ([0-9.:]+)\D\d+: zone transfer '(.*)\/.XFR\/IN' denied$/ |
|---|
| 249 | mail=sysadm,subject=Denied AXFR for zone '$2' from $1 |
|---|
| 250 | threshold type=limit,count=1,seconds=600 |
|---|
| 251 | |
|---|
| 252 | - - - - - - - - - - - - - - - cut above - - - - - - - - - - - - - - |
|---|
| 253 | |
|---|
| 254 | 12. Kill Swatch |
|---|
| 255 | |
|---|
| 256 | $ ps ax | grep swatch |
|---|
| 257 | |
|---|
| 258 | Find the process ID (the number on the left), and run kill on it: |
|---|
| 259 | |
|---|
| 260 | $ sudo kill PID_OF_SWATCH |
|---|
| 261 | |
|---|
| 262 | Restart swatch (switch to root temporarily using the sudo -s command) |
|---|
| 263 | |
|---|
| 264 | $ sudo -s |
|---|
| 265 | # /usr/local/bin/swatch -c /usr/local/etc/swatch.conf --tail-file=/etc/namedb/log/general --daemon |
|---|
| 266 | # exit |
|---|
| 267 | $ |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | Note: Why are we telling swatch to look at the "general" log file ? |
|---|
| 271 | |
|---|
| 272 | If you remember from the previous logging lab, we configured BIND |
|---|
| 273 | to log the security category into the general channel definition. |
|---|
| 274 | Therefore, we need to monitor the /etc/namedb/log/general file. |
|---|
| 275 | |
|---|
| 276 | 13. Re-run the zone transfer as in step 4 (from another machine) and see if |
|---|
| 277 | you receive a mail to the arm user when that happens.: |
|---|
| 278 | |
|---|
| 279 | $ mutt -f /var/mail/sysadm |
|---|
| 280 | |
|---|
| 281 | Try again 2 more times to do AXFR within a minute. |
|---|
| 282 | |
|---|
| 283 | Q: How many mails did you receive? Why? |
|---|
| 284 | |
|---|