Author

The Archives

  • 04.Apr.15
    String manipulation in Bash shell | rafacas | (0)
    I rely on Bash on much of my scripting needs although it is usually not worthy when you need to do something complicated. However, we usually think Bash limits are lower than they really are. In this post I am going to explain the surprising number of string manipulation operations that Bash supports. String Length The syntax to know the lenght of a string is: ${#string} For example: $ string=abcdefghijklmnopqrstuvwxyz $ echo ${#string} 26 Substring Extraction ${string:position} Extracts substring from $string at $position. $ string=abcdefghijklmnopqrstuvwxyz $ echo ${string:1} bcdefghijklmnopqrstuvwxyz Note that strings are zero-based indexed. If you want to extract a substring of a specific length then: ${string:position:length} Extracts $length characters from $string at $position. For example: $ echo ${string:5:3} fgh It ...
  • 09.Feb.15
    Moving a Repository from Bitbucket to GitHub shell | rafacas | (4)
    Some people have asked me how they can move a repository from Bitbucket to Github (or vice versa). To know how to do it we need to understand Git’s remote repositories. Remote repositories are versions of your project that are hosted on the Internet or network somewhere (you can have several of them). First, let’s clone the Bitbucket repository: $ git clone https://bitbucket.org/rafacas/test.git Cloning into ’test'... remote: Counting objects: 124, done. remote: Compressing objects: 100% (120/120), done. remote: Total 124 (delta 42), reused 0 (delta 0) Receiving objects: 100% (124/124), 1.31 MiB | 541.00 KiB/s, done. Resolving deltas: 100% (42/42), done. Checking connectivity... done. To see which remote servers you ...
  • 04.Feb.15
    Editing Binary Files shell | rafacas | (0)
    In a previous post we learnt how to back up the MBR of a hard disk in a file called mbr.img. That file has the first 512 bytes (the first sector) of the hard disk. One way to see the content of a binary file is dumping it to hexadecimal. In Linux the xxd command makes a hex dump: $ xxd mbr.img 0000000: eb63 9010 8ed0 bc00 b0b8 0000 8ed8 8ec0 .c.............. 0000010: fbbe 007c bf00 06b9 0002 f3a4 ea21 0600 ...|.........!.. 0000020: 00be be07 3804 750b 83c6 1081 fefe 0775 ....8.u........u 0000030: f3eb 16b4 02b0 01bb 007c b280 8a74 018b .........|...t.. 0000040: 4c02 ...
  • 02.Feb.15
    Find Integrated Lights-Out IPs in a network shell | rafacas | (0)
    Integrated Lights-Out, or iLO, is a proprietary embedded server management technology by Hewlett-Packard which provides out-of-band management facilities. The physical connection is an Ethernet port that can be found on most Proliant servers of the 300 and above series. It is very useful because it allows to perform activities on an HP server from a remote location. The iLO card has a separate network connection (and its own IP address) to which one can connect via HTTPS. Some of the options I have used are: Reset the server (very useful when the server doesn't respond anymore via the normal network card). Power-up the server ...
  • 30.Jan.15
    Backup & Restore the Master Boot Record shell | rafacas | (0)
    Some days ago I had to recover the Master Boot Record (MBR) of a damaged hard disk. The MBR is the first 512 bytes of a storage device. It contains an operating system boot loader and the storage device’s partition table. If you need to make a backup of the MBR type the following command: dd if=/dev/sda of=/root/mbr.img bs=1 count=512 You only have to change sda with the device name that correponds to your hard disk. To restore it: dd if=/root/mbr.img of=/dev/sda bs=1 count=512 And as before, change sda with the device name that corresponds to the hard disk you are going to restore the MBR ...
  • 28.Jan.15
    GHOST Vulnerability: glibc gethostbyname buffer overflow news, security | rafacas | (0)
    The GHOST vulnerability was discovered and disclosed by Qualys. It is a serious weakness in the Linux glibc library. It allows attackers to remotely take complete control of the victim system without having any prior knowledge of system credentials. CVE-2015-0235 has been assigned to this issue. Qualys researchers discovered a buffer overflow in the __nss_hostname_digits_dots() function of glibc. This bug can be triggered both locally and remotely via all the gethostbyname*() functions. Applications have access to the DNS resolver primarily through the gethostbyname*() set of functions. These functions convert a hostname into an IP address. They have developed a full-fledged remote ...
  • 26.Jan.15
    Extracting a video clip from the command line shell | rafacas | (0)
    I had to extract a small clip from a very long video and I wanted to do it from the command line (of course!). To do that we will use avconv (it is part of libav, an open source audio and video tools). It is a very fast audio and video converter that can be used to extract a clip from a video. To install it in debian based distros: $ sudo apt-get install libav-tools In RedHat based distros there isn’t any source with a decent RPM package so the simplest way is build it from source. In OS X there is a command called ...
  • 25.Dec.14
    Merry Christmas! fun | rafacas | (0)
    /\\,/\\, /| || || || || || _-_ ,._-_ ,._-_ '\\/\\ ||=|= || || \\ || || || ;' ~|| || || ||/ || || ||/ |, \\,\\, \\,/ \\, \\, |/ _- ( ...
  • 05.Aug.12
    How to find alive hosts in our network network | rafacas | (0)
    Sometimes I need to know all the alive hosts' IP addresses in the LAN I am connected. The following command will show that information: $ nmap -n -sP 192.168.10.0/24 Starting Nmap 5.21 ( http://nmap.org ) at 2012-08-05 11:24 BST Nmap scan report for 192.168.10.1 Host is up (0.00086s latency). Nmap scan report for 192.168.10.40 Host is up (0.00057s latency). Nmap scan report for 192.168.10.50 Host is up (0.00056s latency). Nmap scan report for 192.168.10.100 Host is up (0.00051s latency). Nmap done: 256 IP addresses (4 hosts up) scanned in 13.44 seconds The option -sP tells nmap to do a ping scan, that is, to go no further than determining if host ...
  • 22.Sep.11
    How to know if a CPU is 32 or 64-bit shell | rafacas | (0)
    Nowadays almost all the computers have a 64-bit CPU, but sometimes we are logged in on a remote server and do not know what kind of CPU it has and we need to know it to install a package or... out of mere curiosity. In those cases we can run the following command: $ grep --color lm /proc/cpuinfo flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc up ida nonstop_tsc arat pni ssse3 cx16 sse4_1 sse4_2 popcnt lahf_lm If the lm flag ...