Category:
Centos,
Permission — SkyHi @ Friday, November 06, 2009
I needed to get a list of all the subdirectories that were owner by some other user than root under /var and their permissions/owner with full paths. My first thought was to use ls and something like this: ls -dlR */ drwxr-xr-x 2 root root 4096 2009-06-05 06:25 backups/ drwxr-xr-x 8 root root 4096 2009-05-11 06:02 cache/ drwxr-xr-x 2 root root 4096 2009-05-06 04:49 ec2/ drwxr-xr-x 25 root root 4096 2009-05-25 14:55 lib/ ... will show the subdirectories just as I needed but only at one level. Using */*/ would show the next level, etc. This obviously is not a solution and unfortunately I had found no other way to do this with ls. Using: ls -alR | grep ^d drwxr-xr-x 15 root root 4096 2009-05-11 06:02 . drwxr-xr-x 22 root root 4096 2009-06-03 15:02 .. drwxr-xr-x 2 root root 4096 2009-06-05 06:25 backups drwxr-xr-x 8 root root 4096 2009-05-11 06:02 cache drwxr-xr-x 2 root root 4096 2009-05-06 04:49 ec2 drwxr-xr-x 25 root root 4096 2009-05-25 14:55 lib .... works somehow, but since I don’t have the full paths this is useless.
Maybe this can be done with ls, but since I have not found a way to do this, I turned to find. Find allows me very simple to get the list of subdirectories with their full paths: find /var -type d /var /var/backups /var/lib /var/lib/ucf /var/lib/ucf/cache /var/lib/vim /var/lib/vim/addons /var/lib/php5 /var/lib/iptraf /var/lib/mysql-cluster /var/lib/collectd ... and to get also the owner/permissions we can get help from ls: ls -dl `find /var -type d` drwxr-xr-x 15 root root 4096 2009-05-11 06:02 /var drwxr-xr-x 2 root root 4096 2009-06-05 06:25 /var/backups drwxr-xr-x 8 root root 4096 2009-05-11 06:02 /var/cache drwxr-xr-x 3 www-data www-data 4096 2009-05-11 06:02 /var/cache/apache2 drwxr-xr-x 2 www-data www-data 4096 2008-09-08 05:08 /var/cache/apache2/mod_disk_cache drwxr-xr-x 3 root root 4096 2009-06-03 09:32 /var/cache/apt drwxr-xr-x 3 root root 4096 2009-06-03 09:32 /var/cache/apt/archives drwxr-xr-x 2 root root 4096 2009-06-03 09:32 /var/cache/apt/archives/partial drwxr-xr-x 2 root root 4096 2009-06-05 06:25 /var/cache/apt-show-versions drwxr-xr-x 2 root root 4096 2009-06-03 09:32 /var/cache/debconf drwxr-xr-x 2 root root 4096 2009-06-05 06:25 /var/cache/locate drwxr-sr-x 42 man root 4096 2009-06-05 06:25 /var/cache/man ...
And finally the oneliner that gives us all the folders that are owned by some other user as root: ls -dl `find /var -type d` | grep -v root drwxr-xr-x 3 www-data www-data 4096 2009-05-11 06:02 /var/cache/apache2 drwxr-xr-x 2 www-data www-data 4096 2008-09-08 05:08 /var/cache/apache2/mod_disk_cache drwxr-s--- 2 mysql adm 4096 2009-06-05 06:25 /var/log/mysql drwxr-sr-x 2 news news 4096 2009-05-06 04:49 /var/log/news
time for awk now ;)
Update: as per the comment bellow from chlovechek a much cleaner solution is: find /var ! -user root -type d -ls
Category:
iptables,
scripts — SkyHi @ Friday, November 06, 2009
Sometime it is necessary to block incoming connection or traffic from specific remote host. iptables is administration tool for IPv4 packet filtering and NAT under Linux kernel. Following tip will help you to block attacker or spammers IP address. How do I block specific incoming ip address?
Following iptable rule will drop incoming connection from host/IP 202.54.20.22:
iptables -A INPUT -s 202.54.20.22 -j DROP iptables -A OUTPUT -d 202.54.20.22 -j DROP
A simple shell script to block lots of IP address
If you have lots of IP address use the following shell script:
A) Create a text file:
# vi /root/ip.blocked Now append IP address:
# Ip address block file 202.54.20.22 202.54.20.1/24 #65.66.36.87
B) Create a script as follows or add following script line to existing iptables shell script:
BLOCKDB=”/root/ip.blocked” IPS=$(grep -Ev "^#" $BLOCKDB) for i in $IPS do iptables -A INPUT -s $i -j DROP iptables -A OUTPUT -d $i -j DROP done
# For debugging use iptables -v. IPTABLES="/sbin/iptables" IP6TABLES="/sbin/ip6tables" MODPROBE="/sbin/modprobe" RMMOD="/sbin/rmmod" ARP="/usr/sbin/arp"
# Logging options. # Note: We use --log-level debug, so that the messages are not output # to all virtual consoles (which would be quite annoying). # Alternative: Start klogd with -c 4 (e.g. by setting KLOGD="-c 4" in the # /etc/init.d/klogd startup-script. LOG="LOG --log-level debug --log-tcp-sequence --log-tcp-options" LOG="$LOG --log-ip-options"
# Defaults for rate limiting (to prevent DoS attacks and excessive logging). # TODO: What is a good value for --limit and --limit-burst? # TODO: Test rate limiting. RLIMIT="-m limit --limit 3/s --limit-burst 8"
# Disable IP forwarding. # Note: We turn this on and off to reset all settings to their defaults. echo 1 > /proc/sys/net/ipv4/ip_forward echo 0 > /proc/sys/net/ipv4/ip_forward
# Enable IP spoofing protection (i.e. source address verification). # Note: This is special, as it seems to only be enabled if you set # */all/rp_filter AND */eth0/rp_filter (for example) to 1! Setting only # */all/rp_filter alone does _not_ suffice, which is pretty counter-intuitive. for i in /proc/sys/net/ipv4/conf/*/rp_filter; do echo 1 > $i; done
# Protect against SYN flood attacks (see http://cr.yp.to/syncookies.html). echo 1 > /proc/sys/net/ipv4/tcp_syncookies
# Ignore all incoming ICMP echo requests (i.e. disable ping). # Usually not a good idea, as some protocols and users need/want this. # echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all
# Ignore ICMP echo requests to broadcast/multicast addresses. We do not # want to participate in smurf (and similar) DoS attacks. # For details see: http://en.wikipedia.org/wiki/Smurf_attack. echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
# Log packets with impossible addresses. for i in /proc/sys/net/ipv4/conf/*/log_martians; do echo 1 > $i; done
# Don't log invalid responses to broadcast frames, they just clutter the logs. echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
# Don't accept or send ICMP redirects. for i in /proc/sys/net/ipv4/conf/*/accept_redirects; do echo 0 > $i; done for i in /proc/sys/net/ipv4/conf/*/send_redirects; do echo 0 > $i; done
# Don't accept source routed packets. for i in /proc/sys/net/ipv4/conf/*/accept_source_route; do echo 0 > $i; done
# Disable multicast routing. Should not be needed, usually. # TODO: This throws an "Operation not permitted" error. Why? # for i in /proc/sys/net/ipv4/conf/*/mc_forwarding; do echo 0 > $i; done
# Disable proxy_arp. Should not be needed, usually. for i in /proc/sys/net/ipv4/conf/*/proxy_arp; do echo 0 > $i; done
# Enable secure redirects, i.e. only accept ICMP redirects for gateways # listed in the default gateway list. Helps against MITM attacks. for i in /proc/sys/net/ipv4/conf/*/secure_redirects; do echo 1 > $i; done
# Disable bootp_relay. Should not be needed, usually. for i in /proc/sys/net/ipv4/conf/*/bootp_relay; do echo 0 > $i; done
# TODO: These may mitigate ARP poisoning attacks? # /proc/sys/net/ipv4/neigh/*/locktime # /proc/sys/net/ipv4/neigh/*/gc_stale_time
# TODO: Check rest of /usr/src/linux/Documentation/networking/ip-sysctl.txt. # Are there any security-relevant options I missed? Check especially: # icmp_ratelimit, icmp_ratemask, icmp_errors_use_inbound_ifaddr, arp_*.
# Drop everything by default. # Note: The default policies are set _before_ flushing the chains, to prevent # a short timespan between flushing the chains and setting policies where # any traffic would be allowed. $IPTABLES -P INPUT DROP $IPTABLES -P FORWARD DROP $IPTABLES -P OUTPUT DROP
# Set the nat/mangle/raw tables' chains to ACCEPT (we don't use them). # Packets will simply pass through these tables unchanged. # TODO: What happens if the modules aren't loaded? $IPTABLES -t nat -P PREROUTING ACCEPT $IPTABLES -t nat -P OUTPUT ACCEPT $IPTABLES -t nat -P POSTROUTING ACCEPT
# Block all IPv6 traffic, otherwise the firewall might be circumvented by an # attacker who simply sends IPv6 traffic instead of IPv4 traffic. # Note: The safest way to prevent IPv6 traffic is to not enable support for # IPv6 in the kernel in the first place (neither built-in nor as a module).
# If the ip6tables command is available, try to block all IPv6 traffic. if test -x $IP6TABLES; then # Set the default policies (drop everything). $IP6TABLES -P INPUT DROP 2>/dev/null $IP6TABLES -P FORWARD DROP 2>/dev/null $IP6TABLES -P OUTPUT DROP 2>/dev/null
# LOG packets, then ACCEPT them. $IPTABLES -N ACCEPTLOG $IPTABLES -A ACCEPTLOG -j $LOG $RLIMIT --log-prefix "ACCEPT " $IPTABLES -A ACCEPTLOG -j ACCEPT
# LOG packets, then DROP them. $IPTABLES -N DROPLOG $IPTABLES -A DROPLOG -j $LOG $RLIMIT --log-prefix "DROP " $IPTABLES -A DROPLOG -j DROP
# LOG packets, then REJECT them. TCP packets are rejected with a TCP reset. $IPTABLES -N REJECTLOG $IPTABLES -A REJECTLOG -j $LOG $RLIMIT --log-prefix "REJECT " $IPTABLES -A REJECTLOG -p tcp -j REJECT --reject-with tcp-reset $IPTABLES -A REJECTLOG -j REJECT
# A custom chain which only allows minimal (RELATED) ICMP types # (destination-unreachable, time-exceeded, and parameter-problem). # TODO: Rate-limit this traffic? # TODO: Allow fragmentation-needed? # TODO: Test. $IPTABLES -N RELATED_ICMP $IPTABLES -A RELATED_ICMP -p icmp --icmp-type destination-unreachable -j ACCEPT $IPTABLES -A RELATED_ICMP -p icmp --icmp-type time-exceeded -j ACCEPT $IPTABLES -A RELATED_ICMP -p icmp --icmp-type parameter-problem -j ACCEPT $IPTABLES -A RELATED_ICMP -j DROPLOG
#------------------------------------------------------------------------------ # Only allow the minimally required/recommended parts of ICMP. Block the rest. # For details see: # * http://tools.ietf.org/html/792 # * http://tools.ietf.org/html/1122 # * http://www.iana.org/assignments/icmp-parameters # * http://www.daemon.be/maarten/icmpfilter.html #------------------------------------------------------------------------------
# Note: Be careful if you're using kernels older than 2.4.29. Some locally # generated ICMP error types (going through OUTPUT) are erroneously tagged # as INVALID (instead of RELATED). # Details: http://lists.debian.org/debian-firewall/2006/05/msg00051.html.
# TODO: This section needs a lot of testing!
# First, drop all fragmented ICMP packets (almost always malicious). $IPTABLES -A INPUT -p icmp --fragment -j DROPLOG $IPTABLES -A OUTPUT -p icmp --fragment -j DROPLOG $IPTABLES -A FORWARD -p icmp --fragment -j DROPLOG
# Allow all ESTABLISHED ICMP traffic. # TODO: Tighten this some more? $IPTABLES -A INPUT -p icmp -m state --state ESTABLISHED -j ACCEPT $RLIMIT $IPTABLES -A OUTPUT -p icmp -m state --state ESTABLISHED -j ACCEPT $RLIMIT
# Allow some parts of the RELATED ICMP traffic, block the rest. # TODO: FORWARD? $IPTABLES -A INPUT -p icmp -m state --state RELATED -j RELATED_ICMP $RLIMIT $IPTABLES -A OUTPUT -p icmp -m state --state RELATED -j RELATED_ICMP $RLIMIT
# Allow incoming ICMP echo requests (ping), but only rate-limited. $IPTABLES -A INPUT -p icmp --icmp-type echo-request -j ACCEPT $RLIMIT
# Allow outgoing ICMP echo requests (ping), but only rate-limited. # TODO: Really do rate limiting here? $IPTABLES -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT $RLIMIT
# Drop any other ICMP traffic. $IPTABLES -A INPUT -p icmp -j DROPLOG $IPTABLES -A OUTPUT -p icmp -j DROPLOG $IPTABLES -A FORWARD -p icmp -j DROPLOG
#------------------------------------------------------------------------------ # Selectively allow certain special types of traffic. #------------------------------------------------------------------------------
# Allow all incoming and outgoing connections on the loopback interface. $IPTABLES -A INPUT -i lo -j ACCEPT $IPTABLES -A OUTPUT -o lo -j ACCEPT
# Allow incoming connections related to existing allowed connections. $IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow outgoing connections related to existing allowed connections. $IPTABLES -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Uncomment this (and comment the above line) to allow all outgoing # connections (except for INVALID ones). # $IPTABLES -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
# Drop SMB/CIFS, and related Windows traffic without logging. We don't care. # TODO: I think not all of these use TCP _and_ UDP. Tighten the rules! $IPTABLES -A INPUT -p tcp -m multiport \ --dports 135,137,138,139,445,1433,1434 -j DROP $IPTABLES -A INPUT -p udp -m multiport \ --dports 135,137,138,139,445,1433,1434 -j DROP
# Explicitly drop invalid incoming traffic (use DROPLOG if you want logging). $IPTABLES -A INPUT -m state --state INVALID -j DROP
# Drop invalid outgoing traffic, too. # Note: This may prevent you from performing certain scans. Also, see above # comment about ICMP packets being erroneously marked as INVALID instead of # RELATED in kernels older than 2.4.29. Remove this rule if needed. $IPTABLES -A OUTPUT -m state --state INVALID -j DROP
# This is not needed, as we use policy DROP for FORWARD, and we disabled # ip_forward anyways. However, if we would use NAT, INVALID packets would # bypass our rules, so we block them explicitly here, just in case. $IPTABLES -A FORWARD -m state --state INVALID -j DROP
# Hinder portscanners a bit. $IPTABLES -A INPUT -m state --state NEW -p tcp --tcp-flags ALL ALL -j DROP $IPTABLES -A INPUT -m state --state NEW -p tcp --tcp-flags ALL NONE -j DROP
# TODO: Some more anti-spoofing rules? For example: # TODO: Test. # $IPTABLES -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP # $IPTABLES -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP # $IPTABLES -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
# TODO: Block known-bad IPs (see http://www.dshield.org/top10.php). # $IPTABLES -A INPUT -s INSERT-BAD-IP-HERE -j DROPLOG
#------------------------------------------------------------------------------ # Drop any traffic from IANA-reserved IPs. # Note: You could easily block valid traffic, e.g. if your ISP uses private # addresses (see RFC 1918) in their network. If in doubt, remove these rules. # For details see: # * ftp://ftp.iana.org/assignments/ipv4-address-space # * http://www.cymru.com/Documents/bogon-bn-agg.txt #------------------------------------------------------------------------------
$IPTABLES -A INPUT -s 0.0.0.0/7 -j DROP $IPTABLES -A INPUT -s 2.0.0.0/8 -j DROP $IPTABLES -A INPUT -s 5.0.0.0/8 -j DROP $IPTABLES -A INPUT -s 7.0.0.0/8 -j DROP $IPTABLES -A INPUT -s 10.0.0.0/8 -j DROP $IPTABLES -A INPUT -s 23.0.0.0/8 -j DROP $IPTABLES -A INPUT -s 27.0.0.0/8 -j DROP $IPTABLES -A INPUT -s 31.0.0.0/8 -j DROP $IPTABLES -A INPUT -s 36.0.0.0/7 -j DROP $IPTABLES -A INPUT -s 39.0.0.0/8 -j DROP $IPTABLES -A INPUT -s 42.0.0.0/8 -j DROP $IPTABLES -A INPUT -s 49.0.0.0/8 -j DROP $IPTABLES -A INPUT -s 50.0.0.0/8 -j DROP $IPTABLES -A INPUT -s 77.0.0.0/8 -j DROP $IPTABLES -A INPUT -s 78.0.0.0/7 -j DROP $IPTABLES -A INPUT -s 92.0.0.0/6 -j DROP $IPTABLES -A INPUT -s 96.0.0.0/4 -j DROP $IPTABLES -A INPUT -s 112.0.0.0/5 -j DROP $IPTABLES -A INPUT -s 120.0.0.0/8 -j DROP # $IPTABLES -A INPUT -s 127.0.0.0/8 -j DROP $IPTABLES -A INPUT -s 169.254.0.0/16 -j DROP $IPTABLES -A INPUT -s 172.16.0.0/12 -j DROP $IPTABLES -A INPUT -s 173.0.0.0/8 -j DROP $IPTABLES -A INPUT -s 174.0.0.0/7 -j DROP $IPTABLES -A INPUT -s 176.0.0.0/5 -j DROP $IPTABLES -A INPUT -s 184.0.0.0/6 -j DROP $IPTABLES -A INPUT -s 192.0.2.0/24 -j DROP # $IPTABLES -A INPUT -s 192.168.0.0/16 -j DROP $IPTABLES -A INPUT -s 197.0.0.0/8 -j DROP $IPTABLES -A INPUT -s 198.18.0.0/15 -j DROP $IPTABLES -A INPUT -s 223.0.0.0/8 -j DROP $IPTABLES -A INPUT -s 224.0.0.0/3 -j DROP
#------------------------------------------------------------------------------ # Selectively allow certain outbound connections, block the rest. # TODO: This could be tightened a bit more (limit source/dest port ranges). #------------------------------------------------------------------------------
# Allow outgoing DNS requests. Few things will work without this. $IPTABLES -A OUTPUT -m state --state NEW -p udp --dport 53 -j ACCEPT $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 53 -j ACCEPT
# Allow outgoing HTTP requests. Unencrypted, use with care. $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
# Allow outgoing HTTPS requests. $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT
# Allow outgoing SMTPS requests. Do NOT allow unencrypted SMTP! # $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 465 -j ACCEPT
# Allow outgoing "submission" requests. # Submission (RFC 2476) is used for sending email, and uses port 587. # This can be encrypted or unencrypted, depending on the server (I think). $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 587 -j ACCEPT
# Allow outgoing POP3S requests. Do NOT allow unencrypted POP3! $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 995 -j ACCEPT
# Allow outgoing SSH requests. $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 22 -j ACCEPT
# Allow outgoing FTP requests. Unencrypted, use with care. # Note: This usually needs the ip_conntrack_ftp kernel module. $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 21 -j ACCEPT
# Allow outgoing NNTP requests. Unencrypted, use with care. $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 119 -j ACCEPT
# Allow outgoing NTP requests. Unencrypted, use with care. $IPTABLES -A OUTPUT -m state --state NEW -p udp --dport 123 -j ACCEPT
# Allow outgoing IRC requests. Unencrypted, use with care. # Note: This usually needs the ip_conntrack_irc kernel module. $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 6667 -j ACCEPT
# Allow outgoing requests to various proxies. Unencrypted, use with care. $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 8080 -j ACCEPT $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 8090 -j ACCEPT
# Allow outgoing DHCP requests. Unencrypted, use with care. # TODO: This is completely untested, I have no idea whether it works! # TODO: I think this can be tightened a bit more. $IPTABLES -A OUTPUT -m state --state NEW -p udp \ --sport 67:68 --dport 67:68 -j ACCEPT
# Allow outgoing CVS requests. Unencrypted, use with care. $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 2401 -j ACCEPT
# Allow outgoing SVN requests. Unencrypted, use with care. $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 3690 -j ACCEPT
# Allow outgoing Tor (http://tor.eff.org) requests. # Note: Do _not_ use unencrypted protocols over Tor (sniffing is possible)! $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 9001 -j ACCEPT $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 9002 -j ACCEPT $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 9030 -j ACCEPT $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 9031 -j ACCEPT $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 9090 -j ACCEPT $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 9091 -j ACCEPT
# Allow outgoing Bacula (http://www.bacula.org) requests. # Unencrypted (usually), use with care. # Ports: Console -> DIR:9101, DIR -> SD:9103, DIR -> FD:9102, FD -> SD:9103 $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 9101 -j ACCEPT # $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 9103 -j ACCEPT # $IPTABLES -A OUTPUT -m state --state NEW -p tcp --dport 9102:9103 -j ACCEPT
# Allow outgoing OpenVPN requests. $IPTABLES -A OUTPUT -m state --state NEW -p udp --dport 1194 -j ACCEPT
# TODO: ICQ, ...
#------------------------------------------------------------------------------ # Selectively allow certain inbound connections, block the rest. # TODO: This could be tightened a bit more (limit source/dest port ranges). #------------------------------------------------------------------------------
# Allow incoming DNS requests. # $IPTABLES -A INPUT -m state --state NEW -p udp --dport 53 -j ACCEPT # $IPTABLES -A INPUT -m state --state NEW -p tcp --dport 53 -j ACCEPT
# Allow incoming HTTP requests. # $IPTABLES -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
# Allow incoming HTTPS requests. # $IPTABLES -A INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT
# Allow incoming POP3 requests. # $IPTABLES -A INPUT -m state --state NEW -p tcp --dport 110 -j ACCEPT
# Allow incoming POP3S requests. # $IPTABLES -A INPUT -m state --state NEW -p tcp --dport 995 -j ACCEPT
# Allow incoming SMTP requests. # $IPTABLES -A INPUT -m state --state NEW -p tcp --dport 25 -j ACCEPT
# Allow incoming SSH requests. # $IPTABLES -A INPUT -m state --state NEW -p tcp --dport 22 -j ACCEPT
# Allow incoming FTP requests. # $IPTABLES -A INPUT -m state --state NEW -p tcp --dport 21 -j ACCEPT
# Allow incoming NNTP requests. # $IPTABLES -A INPUT -m state --state NEW -p tcp --dport 119 -j ACCEPT
# Allow incoming BitTorrent requests. # TODO: Are these already handled by ACCEPTing established/related traffic? # $IPTABLES -A INPUT -m state --state NEW -p tcp --dport 6881 -j ACCEPT # $IPTABLES -A INPUT -m state --state NEW -p udp --dport 6881 -j ACCEPT
# Allow incoming nc requests. # $IPTABLES -A INPUT -m state --state NEW -p tcp --dport 2030 -j ACCEPT # $IPTABLES -A INPUT -m state --state NEW -p udp --dport 2030 -j ACCEPT
# Allow incoming Bacula (http://www.bacula.org) requests. # Ports: Console -> DIR:9101, DIR -> SD:9103, DIR -> FD:9102, FD -> SD:9103 # $IPTABLES -A INPUT -m state --state NEW -p tcp --dport 9102 -j ACCEPT # $IPTABLES -A INPUT -m state --state NEW -p tcp --dport 9101:9103 -j ACCEPT
#------------------------------------------------------------------------------ # Explicitly log and reject everything else. #------------------------------------------------------------------------------
# Use REJECT instead of REJECTLOG if you don't need/want logging. $IPTABLES -A INPUT -j REJECTLOG $IPTABLES -A OUTPUT -j REJECTLOG $IPTABLES -A FORWARD -j REJECTLOG
#------------------------------------------------------------------------------ # Testing the firewall. #------------------------------------------------------------------------------
# You should check/test that the firewall really works, using for example # iptables -vnL, nmap, ping, telnet, ...
This is a dummy burn, with the drive laser off. After you check the dummy run for errors, by looking at the program output, hit the up arrow, delete '-dummy', Enter. If you need a DOS boot floppy image file: http://www.fdos.org/bootdisks/autogen/FDOEM.144.gz .
You want to find out if your girlfriend is cheating on you, having cyber whoopie, or just misbehaving. Even if the computer is secured with a password you can boot with the:
http://www.efense.com/helix
CD and search the entire drive partition for text strings:
Code:
... will search the whole drive partition for the text string specified between the single quotes. Searching an entire disk partition several times can be quite tedious. This particular command string prints the search results to the screen, with the offset where it is located in the partition. Dd works in the decimal system. Hexdump works in hexidecimal. The output text string is at offset 0x020d0d90h. You convert that to decimal with one of the many calculators found in Linux. This is decimal offset: 34,409,872. We want some manageable numbers, custom designed for speed and ease of use. The decimal disk offset is roughly 34 million, so the data we want to view is 34 MB into the partition. We divide 34,409,872 by some power of 2. Experience says 2^13 is about what we want to get a quotient in the thousands. 34,409,872/8192=~4200. The data we want is 8,192 4,200 byte blocks, OR, 4,200 8,192 byte blocks, into the partition. We check: 4200*8192=34406400; 34,409,872-34406400=3472. This means the following command line will start reading 3,472 bytes before the search string location.
Code:
... and finish reading approximately 4,200 bytes after the string. This will net you 3.4k of disk contents before the search string, and 4.2k after. That's a 7.6k chunk of disk, plenty for what we're doing. With this method you search all the deleted files, any chat activity, and emails. It works no matter what security is being employed on the machine. It works with NTFS, ext2, ext3, reiserfs, swap, and FAT partitions. But, it is illegal to use this method on a computer you aren't authorized to search. People can be sued, or imprisoned for performing unauthorized searches. On a related note, you can search system memory with this method, by substituting
Code:
/dev/mem
for
Code:
/dev/sda2
.
Write system memory to a CD. This is useful for documenting memory contents without contaminating the HDD. I recommend using a CD-RW so you can practice a little. This doesn't involve dd, but it's cool.
Code:
This method records raw, so you have to do a:
Code:
dd if=/dev/hdd | hexdump -C | less
to view the recorded memory. You can also employ the string search method above, substituting
Code:
/dev/hdd
for
Code:
/dev/sda2
.
Code:
dd if=/dev/hdd | hexdump -C | grep 'string'
string is any ascii sequence, hex sequence (must be separated with a space: '55aa09' searches for the hex string '55aa09'),
list:
Code:
'[[:alnum:]]' any alphanumeric characters
'[[:alpha:]]' any alpha character
'[[:digit:]]' any numeric character
'[[:blank:]]' tabs and spaces
'[[:lower:]]' any lower case alpha characters
'[[:upper:]]' any uppercase alpha character
'[[:cntrl:]]' ASCII characters 000 thru 037, and 177 octal
'[[:graph:]]' [:alnum:] and [:punct:]
'[[:punct:]]' any punctuation character ` ! ' # $ % ' ( ) * + - . / : ; < = > ? @ [ \ ] ^ _ { | } ~
'[[:space:]]' tab, newline, vertical tab, form feed, carriage return, and space '[[:xdigit:]]' any hex digit ranges('[a-d]' = any, or all abcd, '[0-9]' = any, or all 0123456789)
Code:
dd if=/dev/sda | hexdump -C | grep '[:punct:]' | less
... will return every line from the
Code:
hexdump -C
output that contains any punctuation characters specified above. It will not gather only punctuation characters.
Back up your MBR:
Code:
dd if=/dev/sda of=mbr.bin count=1
Put this on a floppy you make with:
Code:
dd if=boot.img of=/dev/fd0
I back up floppies to a HDD. Floppies don't last forever, so I do:
Code:
dd will not duplicate or erase an HPA, OR, host protected area. Dd will erase a disk completely, but not as well as using the hardware secure erase, security erase unit command
Dd need not be black boxed like other inexpensive forensic software:
http://www.cftt.nist.gov/
For a low cost bootable CD based professional ghosting solution, that supports all operating systems and file systems:
http://www.feyrer.de/g4u/
Variation of dd for data rescue off defective media:
http://www.garloff.de/kurt/linux/ddrescue/
Department of Defense implementation of dd:
http://dcfldd.sourceforge.net/
Sdd is useful when input block size is different than output block size, and will succeed in some instances where dd fails:
http://linux.maruhn.com/sec/sdd.html
This is one of the best links I haven't written about dd:
http://www.softpanorama.org/Tools/dd.shtml
Copyright 2008 by AwesomeMachine.
All Rights Reserved.
Public Domain Copyright Material Begins Here:
Note that sending a SIGUSR1 signal to a running 'dd' process makes it
print to standard error the number of records read and written so far,
then to resume copying.
BLOCKS and BYTES may be followed by the following multiplicative suffixes: c 1, w 2, b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024
So,
Code:
dd if=/dev/sda of=/dev/sdb bs=1GB
Will use one gigabyte block sizes.
bs=4b would give dd a block size of 4 disk sectors. 1 sector=512 bytes.
bs=4k would indicate dd use a 4 kilobyte block size. I have found bs=4k to be the fastest for copying disk drives on a modern machine.
OPERANDS The following operands are supported:
Code:
if=file
Specifies the input path. Standard input is the default.
Code:
of=file
Specifies the output path.
Standard output is the default.
seek=blocks Skip this many blocks in the output file.
Code:
ibs=n
Specifies the input block size in n bytes (default is 512).
Code:
obs=n
Specifies the output block size in n bytes (default is 512).
If no conversion other than
Code:
sync, noerror, and, notrunc
is specified, each input block is copied to the output as a single block without aggregating short blocks.
Code:
cbs=n
Specifies the conversion block size for block and unblock in bytes by n (default is 0). If cbs= is omitted or given a value of 0, using
Code:
block or unblock
produces unspecified results. This option is used only if ASCII or EBCDIC conversion is specified.
Code:
ascii and asciib
operands, the input is handled as described for the unblock operand except that characters are converted to ASCII before the trailing SPACE characters are deleted.
Code:
ebcdic, ebcdicb, ibm, and ibmb
operands, the input is handled as described for the block operand except that the characters are converted to EBCDIC or IBM EBCDIC after the trailing SPACE characters are added.
Code:
files=n
Copies and concatenates n input files before terminating (makes sense only where input is a magnetic tape or similar device).
Code:
skip=n
Skips n input blocks (using the specified input block size) before starting to copy. On seekable files, the implementation reads the blocks or seeks past them. On non-seekable files, the blocks are read and the data is discarded.
Code:
iseek=n
Seeks n blocks from beginning of input file before copying (appropriate for disk files, where skip can be incredibly slow).
Code:
oseek=n
Seeks n blocks from beginning of output file before copying.
Code:
seek=n
Skips n blocks (using the specified output block size) from beginning of output file before copying. On non-seekable files, existing blocks are read and space from the current end-of-file to the specified offset, if any, is filled with null bytes. On seekable files, the implementation seeks to the specified offset or reads the blocks as described for non-seekable files.
Code:
count=n
Copies only n input blocks.
Code:
conv=value
[,value. . . ] Where values are comma-separated symbols from the following list:
Code:
conv=notrunc
Tells dd not to abbreviate blocks of all zero value, or multiple adjacent blocks of zeroes, with five asterisks (when you want to maintain size) Do not use notrunc for copying a larger volume to a smaller volume. Without
Code:
conv=notrunc
Do not truncate the output file.
Code:
ascii
Converts EBCDIC to ASCII.
Code:
asciib
Converts EBCDIC to ASCII using BSD-compatible character translations.
Code:
ebcdic
Converts ASCII to EBCDIC. If converting fixed-length ASCII records without NEWLINEs, sets up a pipeline with
Code:
dd conv=unblock
beforehand.
Code:
ebcdicb
Converts ASCII to EBCDIC using BSD-compatible character translations. If converting fixed-length ASCII records without NEWLINEs, sets up a pipeline with
Code:
dd conv=unblock
beforehand.
Code:
ibm
Slightly different map of ASCII to EBCDIC. If converting fixed-length ASCII records without NEWLINEs, sets up a pipeline with dd
Code:
dd conv=unblock
beforehand.
Code:
ibmb
Slightly different map of ASCII to EBCDIC using BSD-compatible character translations. If converting fixed-length ASCII records without NEWLINEs, sets up a pipeline with
Code:
dd conv=unblock
beforehand. The
Code:
ascii (or asciib), ebcdic (or ebcdicb), and ibm (or ibmb)
values are mutually exclusive. block Treats the input as a sequence of NEWLINE-terminated or EOF-terminated variable-length records independent of the input block boundaries. Each record is converted to a record with a fixed length specified by the conversion block size. Any NEWLINE character is removed from the input line. SPACE characters are appended to lines that are shorter than their conversion block size to fill the block. Lines that are longer than the conversion block size are truncated to the largest number of characters that will fit into that size. The number of truncated lines is reported. unblock Converts fixed-length records to variable length. Reads a number of bytes equal to the conversion block size (or the number of bytes remaining in the input, if less than the conversion block size), delete all trailing SPACE characters, and append a NEWLINE character. The block and unblock values are mutually exclusive.
Code:
lcase
Maps upper-case characters specified by the LC_CTYPE keyword tolower to the corresponding lower-case character. Characters for which no mapping is specified are not modified by this conversion.
Code:
ucase
Maps lower-case characters specified by the LC_CTYPE keyword toupper to the corresponding upper-case character. Characters for which no mapping is specified are not modified by this conversion. The lcase and ucase symbols are mutually exclusive.
Code:
swab
Swaps every pair of input bytes. If the current input record is an odd number of bytes, the last byte in the input record is ignored.
Code:
noerror
Does not stop processing on an input error. When an input error occurs, a diagnostic message is written on standard error, followed by the current input and output block counts in the same format as used at completion. If the
Code:
sync
conversion is specified, the missing input is replaced with null bytes and processed normally. Otherwise, the input block will be omitted from the output. notrunc Does not truncate the output file. Preserves blocks in the output file not explicitly written by this invocation of dd. (See also the preceding
Code:
of=file
operand.)
Code:
sync
Pads every input block to the size of the ibs= buffer, appending null bytes. (If either block or unblock is also specified, appends SPACE characters, rather than null bytes.)
ENVIRONMENT VARIABLES
The following environment variables affect the messages and errors messages of dd:
Code:
LANG
Provide a default value for the internationalisation variables that are unset or null. If
Code:
LANG
is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
Code:
LC_ALL
If set to a non-empty string value, override the values of all the other internationalisation variables.
Code:
LC_CTYPE
Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), the classification of characters as upper- or lower-case, and the mapping of characters from one case to the other.
Code:
LC_MESSAGES
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output.
Code:
NLSPATH
Determine the location of message catalogues for the processing of LC_MESSAGES.
Category:
clone migrate — SkyHi @ Thursday, November 05, 2009
This document is made to be easily skimmed. The latest addition was on 5-21-2009, 'DVD backup of hard drive partition'. This is comprehensive documentation for one of the most useful Linux/UNIX Windows commands-dd. It is a bit-stream duplicator for duplicating data. If you have a question, post it.
First Time visitors please leave a reply.
New Content, for a while at least.DVD backup of hard drive partition: Code:
You wrote chat messages and emails on your girlfriend's computer. You deleted everything. But you want to make sure a private investigator and/or computer consultant can't find it. Code:
dd if=/dev/sda | sed 's/Wendy/Janet/g' | dd of=/dev/sda
Where every instance of Wendy is replaced by Janet, over every millimeter of disk. I picked names with the same number of characters, but you can just pad a smaller name with blanks.
Windows users will find help about 50 lines down from here.
FYI: duplicateing smaller partition, or drive to larger partition, or drive; or vice versa: Code:
You want to duplicate the root directory tree to another drive, but the other drive is larger. If you use dd, you will get a file system that is smaller then the larger destination drive. To duplicate files, not the file system: Format and mount the destination drive: Code:
man parted rsync -avH --exclude=/mnt/destination_drive/ /* /mnt/destination_drive/
will duplicate all the files as files. You need to run: Code:
grub-install update-grub
from a the rescue menu of an installation CD/DVD for the target to become bootable. If target was previously bootable, it remains bootable.
MS Windows Section
Use dd for drive cloning, backup, upgrading, and restore tasks. Boot a Windows XP machine with a Knoppix CD; A live CD Linux system. Download Knoppix, burn the iso image file to a CD, boot with it, and clone drives. Drives are described to the dd command using device files. Boot into Knoppix, and open a root shell. It's in the penguin menu. (80 conductor grey ribbon cable) = /dev/hda for master; /dev/hdb for slave. SATA are /dev/sda and /dev/sdb.
Code:
fdisk -l /dev/hda
The partitions on the first drive. Code:
man fdisk
The manual page for fdisk. Parted to make partitions Code:
man parted
If one has trouble, ask. Knoppix is slow, because it runs on a CD drive (1/1000 the speed of a HDD). Feel free to read the entire post. Dd is not presently able to clone Microsoft Windows Vista OEM Partitions. End Section
Linux DD The basic command structure is as follows: Code:
dd if= of= bs=("USUALLY" some power of 2, not less than 512 bytes(ie, 512, 1024, 2048, 4096, 8192, 16384[/b], but can be ANY reasonable number.) skip= seek= conv=.
Source is the data being read. Target is where the data gets written.
Warning!! If you reverse the source and target, you can wipe out a lot of data. This feature has inspired the nickname "dd" Data Destroyer. Warning!! Caution should be observed when using dd to duplicate encrypted partitions.
Examples: duplicate one hard disk partition to another hard disk: Code:
sda2 and sdb2 are partitions. You want to duplicate sda2 to sdb2. If sdb2 doesn't exist, dd will start at the beginning of the disk, and create it. Be careful with order of if and of. You can write a blank disk to a good disk if you get confused. If you duplicate a smaller partition to a larger one the larger one, using dd, the larger one will now be formatted the same as the smaller one, and there won't be any space left on the drive. The way around this is to use Code:
rsync
, as described in the beginning of the post Make an iso image of a CD: Code:
The 18b specifies 18 sectors of 512 bytes. 2x multiplies the sector size by the number of heads. 80x specifies cylinders--a total of 1474560 bytes. This issues a single 1474560-byte read request to /dev/fd0 and a single 1474560 write request to Code:
/home/sam/floppy.image
. Thanks to Sam Cheeseman for documenting this unusual, but highly cool CHS method of specifying the block size (bs=) parameter of dd. This makes a hard drive image of the floppy, with bootable info intact. The second example uses default bs=512: 1.44 MB floppy sector size. If you're concerned about spies with superconducting quantum-interference detectors, you can always add a "for" loop for US Government DoD approved secure hard disk erasure. Copy and paste the following two lines into a text editor. Code:
#!/bin/bash for n in `seq 7`; do dd if=/dev/urandom of=/dev/sda bs=8b conv=notrunc; done
Save the file as 'swqid'. Code:
chmod a+x swqid
Don't run the program until you are want to wipe the drive. Overwrite the drive with zeroes Code:
dd if=/dev/zero of=/dev/sda bs=4k conv=notrunc
[color="red"I just want to make sure my drive is really zeroed out!![/color] Code:
dd if=/dev/sda | hexdump -C | grep [^00]
... will show every line from the Code:
hexdump -C
that isn't 0x00h, OR, zero To be revised at a later date: To make a bootable flash drive: Download 50 MB Debian based distro here: http://sourceforge.net/projects/insert/
Plug in the thumb drive into a USB port. Do: Code:
dmesg | tail
Look where the new drive is, sdb1, or something similar. Do: Code:
/dev/sda is the source. /dev/sdb is the target. Do not reverse the intended source and target. It happens. Notrunc means 'do not truncate the output file'. Noerror means to keep going if there is an error. Normally dd stops at any error. Duplicate MBR only: Code:
This will duplicate the first 446 bytes of the hard drive to a file. If you haven't already guessed, reversing the objects of if and of, on the dd command line, reverses the direction of the write. Wipe a hard drive: (Boot from a live CD distro to do this.) http://www.efense.com/helix is a good boot CD. The helix boot environment contains the DoD version of dd called dcfldd. It works the same way, but is has a progress bar. Code:
dcfldd if=/dev/zero of=/dev/sda conv=notrunc
Beware, dcfldd does not observe the 'seek=' parameter. This is useful for making the drive almost like new. Most drives have 0xffh written to every byte, from the factory. Overwrite all the free space on a partition (deleted files you don't want recovered) Code:
When dd says no room left on device, all the free space has been overwritten with random characters. Then, delete the big file with Code:
rm
. Code:
less /home/sam/file.bin
looks like GobblDeeGook, because it's a binary file. Code:
dd if=/home/sam/file.bin | hexdump -C | less
is readable. Sometimes one wants to look inside a binary file, with no idea of what they are looking for, only clues to what tools made the file, how to uncompress it, the header bytes, or the author's name and/or email. Virtual memory: Code:
dd if=/proc/kcore | hexdump -C | less
use PgUp, PgDn, up arrow, down arrow to navigate in less. Less is my favorite editor, except you can't edit with it. Filesystems: Code:
dd if=/proc/filesystems | hexdump -C | less
Modules: Code:
dd if=/proc/kallsyms | hexdump -C | less
Interrupt table: Code:
dd if=/proc/interrupts | hexdump -C | less
Uptime (seconds): Code:
dd if=/proc/uptime | hexdump -C | less
Partitions (in KB): Code:
dd if=/proc/partitions | hexdump -C | less
Memory stats: Code:
dd if=/proc/meminfo | hexdump -C | less
I put two identical drives in every one of my machines. Before I do anything that most probably spells disaster, like an untested command line in a root shell, that contains Code:
and I get everything back exactly the same as before whatever daring maneuver I was trying didn't work. You can really, really learn linux this way, because you can't wreck what you have an exact duplicate of. You also might consider making the root partition separate from /home, and make /home big enough to hold the root partition, plus more. Then you can do: Code:
dd if=/dev/sda2 (root) of /home/sam/root.img bs=4096 conv=notrunc,noerror
To make a backup of root, and : Code:
dd if /home/sam/root.img of=/dev/sda2 (root) bs=4096 conv=notrunc,noerror
To write the image of root back to the root partition if you messed up and can't launch the X server, or edited /etc/fstab and can't figure out what you did wrong. It only takes a few minutes to restore a 15 GB root partition from an image file.
How to make a swap file, or another swapfile on a running system: Code:
When dd finishes it outputs (total size)/(total time). You get the idea. Play with 'bs=' and 'count=', always having them multiply out to the same toal size. You can calculate bytes/second like this: 1Gb/total seconds = Gb/s. You can get more realistic results using a 3Gb file.
Rejuvenate a hard drive To cure input/output errors experienced when using dd. Over time the data on a drive, especially a drive that hasn't been used for a year or two, grows into larger magnetic flux points than were originally recorded. It becomes more difficult for the drive heads to decipher these magnetic flux points. This results in I/O errors. Sometimes sector 1 goes bad, resulting in a useless drive. Try: Code:
dd if=/dev/sda of=/dev/sda
to rejuvenate the drive. Rewrites all the data on the drive in nice tight magnetic patterns that can then be read properly. The procedure is safe and economical.
/dev/random produces only as many random bits as the entropy pool contains. This yields quality randomness for cryptographic keys. If more random bytes are required, the process stops until the entropy pool is refilled (waggling your mouse helps). /dev/urandom does not have this restriction. If the user demands more bits than are currently in the entropy pool, it produces them using a pseudo random number generator. Here, /dev/urandom is the Linux random byte device. Myrandom is a file.
Randomize data over a file before deleting it: Code:
Make a ramdrive: The Linux kernel makes a number a ramdisks you can make into ramdrives. You have to populate the drive with zeroes like so: Code:
dd if=/dev/zero of=/dev/ram7 bs=1k count=16384
Populates a 16 MB ramdisk. Code:
mke2fs -m0 /dev/ram7 4096
puts a file system on the ramdisk, turning it into a ramdrive. Watch this puppy smoke. Code:
debian:/home/sam # hdparm -t /dev/ram7 /dev/ram7: Timing buffered disk reads: 16 MB in 0.02 seconds = 913.92 MB/sec
You only need to do the timing once, because it's cool. Make the drive again, because hdparm is a little hard on ramdrives. You can mount the ramdrive with: Code:
mkdir /mnt/mem mount /dev/ram7 /mnt/mem
Now you can use the drive like a hard drive. This is particularly superb for working on large documents or programming. You can duplicate the large file or programming project to the ramdrive, which on my machine is at least 27 times as fast as /dev/sda, and every time you save the huge document, or need to do a compile, it's like your machine is running on nitromethane. The only drawback is data security. The ramdrive is volatile. If you lose power, or lock up, the data on the ramdrive is lost. Use a reliable machine during clear skies if you use a ramdrive.
Duplicate ram memory to a file: Code:
dd if=/dev/mem of=/home/sam/mem.bin bs=1024
The device Code:
/dev/mem
is your system memory. You can actually duplicate any block or character device to a file using dd. Memory capture on a fast system, with bs=1024 takes about 60 seconds, a 120 GB HDD about an hour, a CD to hard drive about 10 minutes, a floppy to a hard drive about 2 minutes. With dd, your floppy drive images will not change. If you have a bootable DOS diskette, and you save it to your HDD as an image file, when you restore that image to another floppy it will be bootable.
Dd will print to the terminal window if you omit the Code:
of=/dev/output
part. Code:
dd if=/home/sam/myfile
will print the file myfile to the terminal window.
This will overwrite all unprotected memory structures with zeroes, and freeze the machine so you have to reboot (Caution, this also prevents committment of the file system journal, and could trash the file system).
You can get arrested in 17 states for doing this next thing. Make an AES encrypted loop device: Code:
to make 'aes-drv' look like a 400 MB file of random bytes. Every time the lo interface is configured using losetup, according to the above, and the file 'aes-drv' is mounted, as above, the porno stash will be accessible in /aes/porno. You don't need to repeat the dd command, OR, the format with reiserfs, OR, the mv command. You only do those steps once. If you forget the password, there is no way to recover it besides guessing. Once the password is set, it can't be changed. To change the password, make a new file with the desired password, and move everything from the old file to the new file. Acl is a good mount option, because it allows use of acls. Otherwise your stuck with u,g,o and rwx.
If you are curious about what might be on you disk drive, or what an MBR looks like, or maybe what is at the very end of your disk: Code:
dd if=/dev/sda count=1 | hexdump -C
Will show you sector 1, or the MBR. The bootstrap code and partition table are in the MBR. To see the end of the disk you have to know the total number of sectors, and the MAS must be set equal to the MNA. The helix CD has a utility to set this correctly. In the dd command, your skip value will be one less than MNA of the disk. For a 120 GB Seagate SATA drives Code:
, So this reads sector for sector, and writes the last sector to myfile. Even with LBA addressing, disks still secretly are read in sectors, cylinders, and heads. There are 63 sectors per track, and 255 heads per cylinder. There is a total cylinder count. 512_bytes/sector*63_sectors/track*255heads=16065*512bytes/cylinder=8,225,280_bytes/cylinder. 63_sectors/track*255_heads=sectors/cylinder. With 234441647 total sectors, and 16065 sectors per cylinder, you get some trailing sectors which do not make up an entire cylinder: 14593.317584812_cylinders/drive. This leaves 5102 sectors which cannot be partitioned, because to be in a partition you have to be a whole cylinder. It's like having part of a person. That doesn't really count as a person. These become surplus sectors after the last partition. You can't ordinarily read past the last partition. But dd can. It's a good idea to check for anything writing to surplus sectors. For our Seagate 120 GB drive, 234,441,647_sectors/drive - 5102_surplus_sectors = 234,436,545 partitionable sectors. Code:
dd if=/dev/sda of=/home/sam/myfile skip=234436545
writes the last 5102 sectors to myfile. Launch midnight commander (mc) to view the file. If there is something in there, you do not need it for anything. In this case you would write over it with random characters: Code:
Will overwrite the 5102 surplus sectors on our 120 GB Seagate drive.
Block size: One cylinder in LBA mode = 255_heads*63_sectors/track=16065_sectors=16065*512_bytes=8,225,280_bytes. The b means '* 512'. 32130b represents a two cylinder block size. Cylinder block size always works to cover every sector in a partition, because partitions are made of a whole number of cylinders. One cylinder is 8,225,280 bytes. If you want to check out some random area of the disk: Code:
Will give you 8,000 sectors in myfile, after the first 16,000 sectors. You can open that file with a hex editor, edit some of it, and write the edited part back to disk: Code:
makes a compressed image file using bzip2 compression. Code:
netcat -l -p 1234 | gzip > partition.img
makes a compressed image file using gzip compression. I back up a 100 GB lappy disk on a desktop drive, over a lan connection, and the 100 GB compresses to about 4.0 GB. Most of the drive is empty, so it's mostly zeroes. Repetitive zeroes compress well. Alert!! Don't hit enter yet. Hit enter on the target machine. THEN hit enter on the source machine.
Netcat is a program, available by default, on most linux installations. It's a networking swiss army knife. In the preceding example, netcat and dd are piped to one another. One of the functions of the linux kernel is to make pipes. The pipe character looks like two little lines on top of one another, both vertical. Here is how this command behaves: This byte size is a cylinder. bs=16065b equals one cylinder on an LBA drive. The dd command is piped to netcat, which takes as its arguments the IP address of the target(like 192.168.0.1, or any IP address with an open port) and what port you want to use(1234).
CONTINUES...SEE NEXT POST
Dd is like Symantec Norton Ghost, Acronis True Image, Symantec Drive Image. You can perform disk drive backup, restore, imaging, disk image, cloning, clone, drive cloning, transfer image, transfer data, clone to another drive or clone to another machine, move Windows XP to a new hard drive, clone Windows XP, clone Windows, transfer Windows, hard drive upgrade, duplicate a boot drive, duplicate a bootable drive, upgrade your operating system hard drive, Tired of reinstalling WinXP Windows XP?
Copyright 2008 by AwesomeMachine. All Rights Reserved.
Category:
Proftpd — SkyHi @ Thursday, November 05, 2009
[root@home ~]# cat /etc/proftpd.conf # This is a basic ProFTPD configuration file (rename it to # 'proftpd.conf' for actual use. It establishes a single server # and a single anonymous login. It assumes that you have a user/group # "nobody" and "ftp" for normal operation and anon. #ServerIdent on " Home server" ServerName "Home ftp server" ServerType standalone DefaultServer on AllowForeignAddress on #RequireValidShell off #TimeoutIdle 3600 #TimeoutStalled 3600 TimeoutLogin 900 TimeoutNoTransfer 3600 UseReverseDNS off IdentLookups off PassivePorts 51000 51999 #TimesGMT off #MasqueradeAddress 192.168.218.48
#UseReverseDNS off #IdentLookups off # Port 21 is the standard FTP port. Port 21
# Umask 022 is a good standard umask to prevent new dirs and files # from being group and world writable. Umask 022
# To prevent DoS attacks, set the maximum number of child processes # to 30. If you need to allow more than 30 concurrent connections # at once, simply increase this value. Note that this ONLY works # in standalone mode, in inetd mode you should use an inetd server # that allows you to limit maximum number of processes per service # (such as xinetd). MaxInstances 30
# Set the user and group under which the server will run. User ftp Group ftp
# To cause every FTP user to be "jailed" (chrooted) into their home # directory, uncomment this line. DefaultRoot ~
# Normally, we want files to be overwriteable. AllowOverwrite on
# Bar use of SITE CHMOD by default DenyAll
# A basic anonymous configuration, no upload directories. If you do not # want anonymous users, simply delete this entire section. #Anonymous ~ftp> #User ftp #Group ftp
# We want clients to be able to login with "anonymous" as well as "ftp" # UserAlias anonymous ftp
# Limit the maximum number of anonymous logins #MaxClients 10
# We want 'welcome.msg' displayed at login, and '.message' displayed # in each newly chdired directory. # DisplayLogin welcome.msg #DisplayFirstChdir .message
# Limit WRITE everywhere in the anonymous chroot # # DenyAll #/Limit> #/Anonymous>
SQLConnectInfo database@192.168.0.16 user password SQLAuthTypes Plaintext Crypt SQLAuthenticate users groups SQLUserInfo ftpuser userid passwd uid gid homedir shell SQLGroupInfo ftpgroup groupname gid members SQLMinID 500 LogFormat default "%h %l %u %t \"%r\" %s %b %D \"%f\"" ExtendedLog /var/www/html/ftp.log ALL default # create a user's home directory on demand if it doesn't exist SQLHomedirOnDemand on
# Update count every time user logs in SQLLog PASS updatecount SQLNamedQuery updatecount UPDATE "count=count+1, accessed=now() WHERE userid='%u '" ftpuser # Update modified everytime user uploads or deletes a file SQLLog STOR,DELE modified SQLNamedQuery modified UPDATE "modified=now() WHERE userid='%u'" ftpuser
Use Mosh instead of SSH
-
Mosh is a replacement for SSH. It's more robust and responsive, especially
over Wi-Fi WiFi, cellular, and long-distance links.
*On Ubuntu:*
# add-apt-repo...
V2V Communications security considerations
-
The future of vehicles, road infrastructure and driving are changing. We
are progressing with vehicle-to-vehicle (V2V) and vehicle-to-infrastructure
(V2I) ...