<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.0">Jekyll</generator><link href="https://fub2.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://fub2.github.io/" rel="alternate" type="text/html" /><updated>2022-01-16T08:35:39+00:00</updated><id>https://fub2.github.io/feed.xml</id><title type="html">Bryan Fu</title><subtitle>Web Developer from Somewhere</subtitle><entry><title type="html">Pipe With Powershell</title><link href="https://fub2.github.io/pipe-with-powershell/" rel="alternate" type="text/html" title="Pipe With Powershell" /><published>2022-01-16T00:00:00+00:00</published><updated>2022-01-16T00:00:00+00:00</updated><id>https://fub2.github.io/pipe-with-powershell</id><content type="html" xml:base="https://fub2.github.io/pipe-with-powershell/">&lt;h1 id=&quot;with-linux-what-we-can-do&quot;&gt;With Linux what we can do:&lt;/h1&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;run_command &amp;lt; input.txt &amp;gt; output.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;with-powershell-on-windows&quot;&gt;With Powershell on Windows&lt;/h1&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Get-content input.txt | run_command.exe | out-file output.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><summary type="html">With Linux what we can do:</summary></entry><entry><title type="html">Ssh Tunneling Explained</title><link href="https://fub2.github.io/ssh-tunneling-explained/" rel="alternate" type="text/html" title="Ssh Tunneling Explained" /><published>2021-12-30T00:00:00+00:00</published><updated>2021-12-30T00:00:00+00:00</updated><id>https://fub2.github.io/ssh-tunneling-explained</id><content type="html" xml:base="https://fub2.github.io/ssh-tunneling-explained/">&lt;p&gt;Excellent post of https://goteleport.com/blog/ssh-tunneling-explained/&lt;/p&gt;

&lt;h3 id=&quot;what-is-ssh-tunneling&quot;&gt;What is SSH tunneling&lt;/h3&gt;

&lt;p&gt;https://goteleport.com/blog/images/2021/ssh-tunnel/ssh-tunnel.png&lt;/p&gt;

&lt;p&gt;For example, during shell access, the data transmitted are binary streams detailing dimensions of pseudo-terminal and ASCII characters to run commands on the remote shell. However, during SSH port forwarding, the data transmitted can be a binary stream of protocol tunneled over SSH (e.g. SQL over SSH).
So SSH tunneling is just a way to transport arbitrary data with a dedicated data stream (tunnel) inside an existing SSH session. This can be achieved with either local port forwarding, remote port forwarding, dynamic port forwarding, or by creating a TUN/TAP tunnel.&lt;/p&gt;</content><author><name></name></author><summary type="html">Excellent post of https://goteleport.com/blog/ssh-tunneling-explained/</summary></entry><entry><title type="html">Freebsd Command</title><link href="https://fub2.github.io/freebsd-command/" rel="alternate" type="text/html" title="Freebsd Command" /><published>2021-09-06T00:00:00+00:00</published><updated>2021-09-06T00:00:00+00:00</updated><id>https://fub2.github.io/freebsd-command</id><content type="html" xml:base="https://fub2.github.io/freebsd-command/">&lt;h3 id=&quot;sysctl-command-to-find-out-how-much-ram-is-installed-on-a-freebsd&quot;&gt;sysctl command to find out how much RAM is installed on a FreeBSD&lt;/h3&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ sysctl hw.physmem
$ sysctl hw | egrep 'hw.(phys|user|real)'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Or
·$ grep memory /var/run/dmesg.boot·&lt;/p&gt;</content><author><name></name></author><summary type="html">sysctl command to find out how much RAM is installed on a FreeBSD $ sysctl hw.physmem $ sysctl hw | egrep 'hw.(phys|user|real)' Or ·$ grep memory /var/run/dmesg.boot·</summary></entry><entry><title type="html">Direct Root Non Root Login</title><link href="https://fub2.github.io/direct-root-non-root-login/" rel="alternate" type="text/html" title="Direct Root Non Root Login" /><published>2019-03-08T00:00:00+00:00</published><updated>2019-03-08T00:00:00+00:00</updated><id>https://fub2.github.io/direct-root-non-root-login</id><content type="html" xml:base="https://fub2.github.io/direct-root-non-root-login/">&lt;h1 id=&quot;how-do-i-secure-ssh-to-disable-direct-rootnon-root-user-login&quot;&gt;How do I secure SSH to disable direct root/non-root user login?&lt;/h1&gt;

&lt;p&gt;Answer :
The procedure described here disallows direct root login, so when you connect using SSH you need to first login as a normal user, then su to obtain root access.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Disabling root login
    &lt;ol&gt;
      &lt;li&gt;Edit the /etc/ssh/sshd_config file with a text editor and find the following line:&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PermitRootLogin yes&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Change the yes to no and remove the ‘#’ at the beginning of the line so that it reads :&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PermitRootLogin no&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Restart the sshd service:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;# service sshd restart&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Disabling direct root login for non-root users&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sometimes allowing all users the ability to remotely log onto a system can be a security risk. There are many ways to limit who can remotely access a system. You can use PAM, IPwrapers, or IPtables to name a few. However, one of the easiest ways to limit who can access a system via SSH is to configure the SSH daemon.
The directive, AllowUsers, can be configured in /etc/ssh/sshd_config. This directive can be followed by the list of user name patterns, separated by spaces. If specified, login is allowed only for those user names.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AllowUsers [username]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Where [username] is the username you want to allow.&lt;/p&gt;

&lt;p&gt;For example, to allow ssh login to users john and teena and disable for it for rest of the users, modify the AllowUsers directive as :&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AllowUsers john teena&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Restart the sshd service for the changes to take effect :&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;# service sshd restart&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Allow / disallow groups ssh login&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To restrict groups, the option AllowGroups and DenyGroups are used in the file /etc/ssh/sshd_config. The said options will allow or disallow users whose primary group or supplementary group matches one of the group patterns.&lt;/p&gt;</content><author><name></name></author><summary type="html">How do I secure SSH to disable direct root/non-root user login?</summary></entry><entry><title type="html">Network Trouble Shooting Tips</title><link href="https://fub2.github.io/network-trouble-shooting-tips/" rel="alternate" type="text/html" title="Network Trouble Shooting Tips" /><published>2018-10-29T00:00:00+00:00</published><updated>2018-10-29T00:00:00+00:00</updated><id>https://fub2.github.io/network-trouble-shooting-tips</id><content type="html" xml:base="https://fub2.github.io/network-trouble-shooting-tips/">&lt;h3 id=&quot;dump-packets-go-in-and-out-to-a-nic-with-specific-mac&quot;&gt;dump packets go in and out to a NIC with specific MAC&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;tcpdump -A -vvv ether host 52:54:BE:8b:2f:92
tcpdump -i tap0 ether host 52:54:be:6b:01:12

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;###&lt;/p&gt;</content><author><name></name></author><summary type="html">dump packets go in and out to a NIC with specific MAC</summary></entry><entry><title type="html">How To Decide Host Is Virtual Or Physical</title><link href="https://fub2.github.io/how-to-decide-host-is-virtual-or-physical/" rel="alternate" type="text/html" title="How To Decide Host Is Virtual Or Physical" /><published>2018-09-27T00:00:00+00:00</published><updated>2018-09-27T00:00:00+00:00</updated><id>https://fub2.github.io/how-to-decide-host-is-virtual-or-physical</id><content type="html" xml:base="https://fub2.github.io/how-to-decide-host-is-virtual-or-physical/">&lt;p&gt;For VMWare stuff:&lt;/p&gt;

&lt;p&gt;https://kb.vmware.com/s/article/1009458&lt;/p&gt;

&lt;h3 id=&quot;testing-the-cpuid-hypervisor-present-bit&quot;&gt;Testing the CPUID hypervisor present bit&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;int cpuid_check() 
{         
    unsigned int eax, ebx, ecx, edx;         
    char hyper_vendor_id[13];          
    cpuid(0x1, &amp;amp;eax, &amp;amp;ebx, &amp;amp;ecx, &amp;amp;edx;;         
    
    if  (bit 31 of ecx is set) {                 
        cpuid(0x40000000, &amp;amp;eax, &amp;amp;ebx, &amp;amp;ecx, &amp;amp;edx;;                 
        memcpy(hyper_vendor_id + 0, &amp;amp;ebx, 4);                 
        memcpy(hyper_vendor_id + 4, &amp;amp;ecx, 4);                 
        memcpy(hyper_vendor_id + 8, &amp;amp;edx, 4);                 
        hyper_vendor_id[12] = '\0';                 
        if (!strcmp(hyper_vendor_id, &quot;VMwareVMware&quot;))                         
        return 1;               // Success - running under VMware         
      }
      
    return 0; 
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;testing-the-virtual-bios-dmi-information-and-the-hypervisor-port&quot;&gt;Testing the virtual BIOS DMI information and the hypervisor port&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;int dmi_check(void) {         
    char string[10];         
    GET_BIOS_SERIAL(string);          
    if (!memcmp(string, &quot;VMware-&quot;, 7) || !memcmp(string, &quot;VMW&quot;, 3))                 
        return 1;                       // DMI contains VMware specific string.         
    else                 
        return 0; 
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;hypervisor-port&quot;&gt;Hypervisor port&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;#define VMWARE_HYPERVISOR_MAGIC 0x564D5868 
#define VMWARE_HYPERVISOR_PORT  0x5658  
#define VMWARE_PORT_CMD_GETVERSION      10  
#define VMWARE_PORT(cmd, eax, ebx, ecx, edx)                            \         
        __asm__(&quot;inl (%%dx)&quot; :                                          \                         
        &quot;=a&quot;(eax), &quot;=c&quot;(ecx), &quot;=d&quot;(edx), &quot;=b&quot;(ebx) :                    \                         
        &quot;0&quot;(VMWARE_HYPERVISOR_MAGIC),                                   \                         
        &quot;1&quot;(VMWARE_PORT_CMD_##cmd),                                     \                         
        &quot;2&quot;(VMWARE_HYPERVISOR_PORT), &quot;3&quot;(UINT_MAX) :                    \                         
        &quot;memory&quot;);  
        
int hypervisor_port_check(void) {         
    uint32_t eax, ebx, ecx, edx;         
    VMWARE_PORT(GETVERSION, eax, ebx, ecx, edx);         
    if (ebx == VMWARE_HYPERVISOR_MAGIC)                 
        return 1;               // Success - running under VMware         
    else                 
        return 0;     
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;complete-solution&quot;&gt;Complete solution&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;int Detect_VMware(void) {         

    if (cpuid_check())                 
        return 1;               // Success running under VMware.         
    else if (dmi_check() &amp;amp;&amp;amp; hypervisor_port_check())                 
        return 1;         
        
    return 0; 
} 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><summary type="html">For VMWare stuff:</summary></entry><entry><title type="html">Unpack Repack Initial Ramdisk</title><link href="https://fub2.github.io/unpack-repack-initial-ramdisk/" rel="alternate" type="text/html" title="Unpack Repack Initial Ramdisk" /><published>2018-09-19T00:00:00+00:00</published><updated>2018-09-19T00:00:00+00:00</updated><id>https://fub2.github.io/unpack-repack-initial-ramdisk</id><content type="html" xml:base="https://fub2.github.io/unpack-repack-initial-ramdisk/">&lt;h3 id=&quot;unpack-initial-ramdisk-in-a-new-folder&quot;&gt;Unpack initial ramdisk in a new folder&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# mkdir test
# cd test
# zcat /boot/initrd-2.6.18-164.6.1.el5.img | cpio -idmv
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After making all necessary changes, use commands to repack and compress initrd image&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# find . | cpio -o -c | gzip -9 &amp;gt; /boot/test.img
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;for-image-compressed-with-xz-format-these-commands-are-to-extract-image&quot;&gt;For image compressed with xz format, these commands are to extract image:&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# mkdir /tmp/initrd
# cd /tmp/initrd
# xz -dc &amp;lt; initrd.img | cpio --quiet -i --make-directories 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then to repack:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# cd /tmp/initrd
# find . 2&amp;gt;/dev/null | cpio --quiet -c -o | xz -9 --format=lzma &amp;gt;&quot;new_initrd.img&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><summary type="html">Unpack initial ramdisk in a new folder</summary></entry><entry><title type="html">Create Pxe Server</title><link href="https://fub2.github.io/create-pxe-server/" rel="alternate" type="text/html" title="Create Pxe Server" /><published>2018-08-07T00:00:00+00:00</published><updated>2018-08-07T00:00:00+00:00</updated><id>https://fub2.github.io/create-pxe-server</id><content type="html" xml:base="https://fub2.github.io/create-pxe-server/">&lt;h3 id=&quot;prepare-software-packages&quot;&gt;Prepare software packages&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  sudo apt update
  apt install isc-dhcp-server
  apt install apache2 tftpd-hpa inetutils-inetd

  wget http://releases.ubuntu.com/xenial/ubuntu-16.04.4-server-amd64.iso
  mount -o loop ubuntu-16.04.4-server-amd64.iso /mnt/cdrom/
  cp -fr /mnt/cdrom/install/netboot/* /var/lib/tftpboot/
  mkdir /var/www/html/xenial-install
  cp -fr /mnt/cdrom/* /var/www/html/xenial-install/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;configure-environment&quot;&gt;Configure environment&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  vim /etc/dhcp/dhcpd.conf
  vim /etc/default/tftpd-hpa 
  vim /etc/inetd.conf
  chmod +w /var/lib/tftpboot/pxelinux.cfg/default
  vim /var/lib/tftpboot/pxelinux.cfg/default
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;dhcpd.conf
```
ddns-update-style none;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;a-slightly-different-configuration-for-an-internal-subnet&quot;&gt;A slightly different configuration for an internal subnet.&lt;/h1&gt;
&lt;p&gt;subnet 10.207.80.0 netmask 255.255.252.0 {
  range 10.207.82.135 10.207.82.136;
  allow booting;
  allow bootp;
  next-server 10.207.80.159;
  filename “pxelinux.0”;
}
option option-128 code 128 = string;
option option-129 code 129 = text;&lt;/p&gt;

&lt;p&gt;host vR730 {
  hardware ethernet 52:54:BE:6b:01:12;
  fixed-address 10.207.82.135;
}&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
* tftpd-hpa
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h1 id=&quot;etcdefaulttftpd-hpa&quot;&gt;/etc/default/tftpd-hpa&lt;/h1&gt;

&lt;p&gt;TFTP_USERNAME=”tftp”
TFTP_DIRECTORY=”/var/lib/tftpboot”
TFTP_ADDRESS=”:69”
TFTP_OPTIONS=”–secure”
RUN_DAEMON=”yes”
OPTIONS=”-l -s /var/lib/tftpboot”&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
* inetd.conf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;tftp dgram udp wait root /usr/sbin/in.tftpd/usr/sbin/in.tftpd -s /var/lib/tftpboot&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
* /var/lib/tftpboot/pxelinux.cfg/default

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h1 id=&quot;d-i-config-version-20&quot;&gt;D-I config version 2.0&lt;/h1&gt;
&lt;h1 id=&quot;search-path-for-the-c32-support-libraries-libcom32-libutil-etc&quot;&gt;search path for the c32 support libraries (libcom32, libutil etc.)&lt;/h1&gt;
&lt;p&gt;path ubuntu-installer/amd64/boot-screens/
include ubuntu-installer/amd64/boot-screens/menu.cfg
default ubuntu-installer/amd64/boot-screens/vesamenu.c32
prompt 0
timeout 0&lt;/p&gt;

&lt;p&gt;[linux]
label linux
kernel ubuntu-installer/amd64/linux
append ks=http://10.207.80.159/ks.cfg vga=normal initrd=ubuntu-installer/amd64/initrd.gz
ramdisk_size=16432 root=/dev/rd/0 rw –&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  
* Start DHCP/TFTP/WWW services  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;375  systemctl restart tftpd-hpa
  376  systemctl status tftpd-hpa&lt;/p&gt;

&lt;p&gt;381  systemctl restart isc-dhcp-server
  382  systemctl status isc-dhcp-server&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
Alternative commands
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;461  /etc/init.d/isc-dhcp-server start 
  463  /etc/init.d/tftpd-hpa start&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
### Debugging command

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;dhcpd -t /etc/dhcp/dhcpd.conf
tcpdump -i ens32 &amp;gt; tcpdump.log
tail -F /var/log/syslog
```&lt;/p&gt;

&lt;p&gt;Error of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cannot bind to local IPv4 socket: Address already in use&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It seems like the problem is that the tftp port (69) is already in use, when you start the tftp server. This might be due to a new program which was installed/updated recently.&lt;/p&gt;

&lt;p&gt;Running the following command will help you figure out which process is using tftp port (69) on your machine:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;netstat -lnp | grep 69&lt;/code&gt;&lt;/p&gt;</content><author><name></name></author><summary type="html">Prepare software packages</summary></entry><entry><title type="html">Mount Qcow2</title><link href="https://fub2.github.io/mount-qcow2/" rel="alternate" type="text/html" title="Mount Qcow2" /><published>2018-07-04T00:00:00+00:00</published><updated>2018-07-04T00:00:00+00:00</updated><id>https://fub2.github.io/mount-qcow2</id><content type="html" xml:base="https://fub2.github.io/mount-qcow2/">&lt;h1 id=&quot;how-to-mount-a-qcow2-disk-image&quot;&gt;How to mount a qcow2 disk image&lt;/h1&gt;

&lt;p&gt;This is a quick guide to mounting a qcow2 disk images on your host server. This is useful to reset passwords,
edit files, or recover something without the virtual machine running.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Step 1 - Enable NBD on the Host&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;apt install qemu-utils 
modprobe nbd max_part=8
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Step 2 - Connect the QCOW2 as network block device&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;qemu-nbd --connect=/dev/nbd0 /var/lib/vz/images/100/vm-100-disk-1.qcow2&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Step 3 - Find The Virtual Machine Partitions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fdisk /dev/nbd0 -l&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Running partx, that should create the /dev/nbd0p* device nodes (assuming they are indeed missing from /dev).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;partx -a /dev/nbd0&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Step 4 - Mount the partition from the VM&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mount /dev/nbd0p1 /mnt/somepoint/&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Step 5 - After you done, unmount and disconnect&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    umount /mnt/somepoint/
    qemu-nbd --disconnect /dev/nbd0
    rmmod nbd
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;mount-unknown-filesystem-type-lvm2_member&quot;&gt;mount: unknown filesystem type LVM2_member&lt;/h1&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;root@svennd:~# mount /dev/sdd2 /mnt/disk`

mount: unknown filesystem type 'LVM2_member'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The fdisk -l already told me its a LVM :&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;root@svennd:~# fdisk -l /dev/sdd
Disk /dev/sdd: 233.8 GiB, 251000193024 bytes, 490234752 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0009345d
Device     Boot  Start       End   Sectors   Size Id Type
/dev/sdd1  *        63    208844    208782   102M 83 Linux
/dev/sdd2       208845 488247479 488038635 232.7G 8e Linux LVM
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;(/dev/sdi1 is /boot partition, /dev/sdi2 is where the /home data resides)&lt;/p&gt;

&lt;p&gt;Seems lvm2 tools also provide a way to check if its lvm or not, using lvmdiskscan (/dev/sdd2 here)&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;root@svennd:~# lvmdiskscan
  /dev/sdb1  [       1.82 TiB]
  /dev/sdc2  [     149.04 GiB]
  /dev/sdd1  [     101.94 MiB]
  /dev/sdd2  [     232.71 GiB] LVM physical volume
  0 disks
  4 partitions
  0 LVM physical volume whole disks
  1 LVM physical volume
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Fine, now lets scan what lv’s are to be found using lvscan&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;root@svennd:~# lvscan
 inactive '/dev/VolGroup00/LogVol00' [230.75 GiB] inherit
 inactive '/dev/VolGroup00/LogVol01' [1.94 GiB] inherit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Since this is a old disk in an enclosure, its not activated on system boot. So we need to “activate” this lvm volume.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;root@svennd:~# vgchange -ay
 2 logical volume(s) in volume group &quot;VolGroup00&quot; now active
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and bam, ready to mount :&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;root@svennd:~# lvscan
  ACTIVE            '/dev/VolGroup00/LogVol00' [230.75 GiB] inherit
  ACTIVE            '/dev/VolGroup00/LogVol01' [1.94 GiB] inherit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;now to mount :&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mount /dev/VolGroup00/LogVol00 /mnt/disk&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;succeed!&lt;/p&gt;</content><author><name></name></author><summary type="html">How to mount a qcow2 disk image</summary></entry><entry><title type="html">Powerful Socat</title><link href="https://fub2.github.io/powerful-socat/" rel="alternate" type="text/html" title="Powerful Socat" /><published>2018-07-04T00:00:00+00:00</published><updated>2018-07-04T00:00:00+00:00</updated><id>https://fub2.github.io/powerful-socat</id><content type="html" xml:base="https://fub2.github.io/powerful-socat/">&lt;p&gt;The socat command shuffles data between two locations. One way to think of socat is as the cat command which transfers data between two locations rather than from a file to standard output. I say that socat works on two locations rather than two files because you can grab data from a network socket, named pipe, or even setup a general virtual network interface as one end point.&lt;/p&gt;

&lt;p&gt;Socat is a tool to manipulate sockets, one input and one output. But the idea of sockets is too restrictive. The documentation speaks about “data channels” which can be combinations of:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;a file&lt;/li&gt;
  &lt;li&gt;a pipe&lt;/li&gt;
  &lt;li&gt;a device (ex: a serial line)&lt;/li&gt;
  &lt;li&gt;a socket (IPv4, IPv6, raw, TCP, UDP, SSL)&lt;/li&gt;
  &lt;li&gt;a FD (STDIN, STDOUT)&lt;/li&gt;
  &lt;li&gt;a program or script&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For each data channel, parameters can be added (port, speed, permissions, owners, etc). For those who use Netcat, the default features remain the same.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Example 1: To exchange data via a TCP session across two hosts:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  hosta$ socat TCP4-LISTEN:31337 OPEN:inputfile,creat,append
  hostb$ cat datafile | socat - TCP4:hosta:31337
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Example 2: To use a local serial line (to configure a network device or access a modem) without a terminal emulator&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  $ socat READLINE,history:/tmp/serial.cmds \
  OPEN:/dev/ttyS0,ispeed=9600,ospeed=9600,crnl,raw,sane,echo=false
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The “READLINE” data channel uses GNU readline to allow editing and reusing input lines like a classic shell.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Example #3: To grab some HTTP content without a browser&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  $ cat &amp;lt;&amp;lt;EOF | socat - TCP4:blog.rootshell.be:80
  GET / HTTP/1.1
  Host: blog.rootshell.be

  EOF
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Example #4: To use Socat to collect Syslog messages&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# socat -u UDP4-LISTEN:5140,reuseaddr,fork OPEN:/tmp/syslog.msg,creat,append
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Example #5: The “EXEC” channel allow us to specify an external program or script. Using the “fdin=” and “fdout=” parameters, it is easy to parse the information received from the input channel and to send back information.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ socat TCP4:12.34.56.78:31337 EXEC:parse.sh,fdin=3,fdout=4
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The following Bash script simulates a web server and can look for suspicious content. If none is found, the visitor is redirected to another site. Note that, for security reasons, “EXEC” does not allow a relative path for the executable. It must be present in your $PATH.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  #!/bin/bash
  #
  # Simple example of honeypot running on HTTP
  # Usage: socat TCP4-LISTEN:80,reuseaddr,fork EXEC:honeypot.sh,fdin=3,fdout=4
  # FD 3 = incoming traffic
  # FD 4 = traffic sent back to the client
  #

  # Define the patterns for bad traffic here
  BADTRAFFIC1=&quot;../../..&quot;
  BADTRAFFIC2=&quot;foobar&quot;

  # Process the received HTTP headers
  while read -u 3 BUFFER
  do
    [ &quot;$BUFFER&quot; = &quot;^M&quot; ] &amp;amp;&amp;amp; break
    echo $BUFFER | egrep -q -o &quot;($BADTRAFFIC1|$BADTRAFFIC2)&quot;
    if [ &quot;$?&quot; = &quot;0&quot; ]; then
      echo &quot;ALERT: Suspicous HTTP: $BUFFER&quot; &amp;gt;&amp;gt;http.log
      cat &amp;lt;END0 &amp;gt;&amp;amp;4
      --html content--
      END0
      exit 0
    fi
  done
  cat &amp;lt;&amp;lt;END1 &amp;gt;&amp;amp;4
  --html content--
  END1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;By using the file descriptors 3 and 4, we can easily read what’s sent by the client and send data into the TCP session.&lt;/p&gt;

&lt;h1 id=&quot;socat-the-general-bidirectional-pipe-handler&quot;&gt;socat: The General Bidirectional Pipe Handler&lt;/h1&gt;

&lt;p&gt;Because socat allows bidirectional data flow between the two locations you specify, it doesn’t really matter which order you specify them in. Locations have the general form of TYPE:options where TYPE can be CREATE, GOPEN or OPEN for normal filesystem files. There are also shortcuts for some locations like STDIO (or just -) which reads and writes to standard input and output respectively.&lt;/p&gt;

&lt;p&gt;The SYSTEM type can be used to execute a program and connect to its standard input and output. For example, the command shown below will run the date command and transfer its output to standard output.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ socat SYSTEM:date -
Thu Apr 23 12:57:00 EST 2009
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Many network services handle control commands using plain text. For example, SMTP servers, HTTP servers. The below socat command will open a connection to a Web server and fetch a page to the console. Notice that the port is specified using the service name and a comma separates the address from the cnrl option which handles line termination transformations for us.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ socat - TCP:localhost:www,crnl
GET /

...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If the network service is more interactive, you might like to use readline to track your command history, improve command editing, and allow you to search and recall your previous commands. Instead of connecting standard IO as the first location in the above command, using READLINE,history=$HOME/.http_history will cause socat to use readline to get your commands.&lt;/p&gt;

&lt;p&gt;Many of the socat location TYPEs take more than one option. For example, GOPEN (generic open) lets you specify append if you would like to append too rather than overwrite the file. The below keeps a log file of the time each time you execute it. This is similar to the Web server example, a comma separated list of additional options for the location.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ date | socat - GOPEN:/tmp/capture,append
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;While this example is quite superfluous in that you could just use the shell » redirection to append to the file, you could also include a network link into the mix with minimal effort using socat as shown below. The first command connects port 3334 on localhost to the file /tmp/capture. The seek-end moves the file to zero bytes from the end and the append makes sure that bytes are appended to the file rather than overwriting it. The client command, shown as the second command below, is very similar to the simpler example shown above except we now send standard IO to a socket address.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ socat TCP4-LISTEN:3334,reuseaddr,fork gopen:/tmp/capture,seek-end=0,append
$ date | socat STDIO tcp:localhost:3334
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;One great use case for socat is making device files from one machine available on another one. I’ll use the example from the socat manual page shown below to demonstrate. The first location creates a PTY device on the local machine allowing raw communication with the other location. The other location is an ssh connection to a server machine, where the standard IO is connected to the serial device on the remote machine.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;(socat PTY,link=$HOME/dev/vmodem0,raw,echo=0,waitslave \
 EXEC:&quot;ssh   modem-server.example.com socat - /dev/ttyS0,nonblock,raw,echo=0&quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;While creating virtual modems is not as attractive as it might once have been, other devices can be moved around too. The below command makes /dev/urandom from a server available through a named pipe on the local machine.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;socat \
  PIPE:/tmp/test/foo  \
  SYSTEM:&quot;ssh myserver socat - /dev/urandom&quot; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Creating a Virtual Private Network over SSH in a Single Line
Virtual networks are created using the TUN device of the Linux kernel. Note that if you send data to a TUN device there is no encryption happening so if those packets move over the real network you have a Virtual Public Network. While there are overviews of using socat with TUN and socat with SSL I think it is much simpler to just use SSH to protect the network link from eavesdropping. You probably already have SSH setup so its much simpler to use because no SSL certificates need to be generated and distributed. The trick with using ssh is how to bolt things together. You could setup port forwarding with ssh and use socat to connect those ports to a virtual TUN device. But that leaves forwarded ports between the two hosts which serve no legitimate purpose other than servicing the socat TUN devices.&lt;/p&gt;

&lt;p&gt;It is clear that one end point will be a direct TUN location, and the other is leaning towards being an ssh into the remote host. The trick is making the ssh into the remote host use socat to connect its standard IO to a TUN device. So we use socat twice in the one command: once to connect a TUN to an ssh session on the local machine, and once to connect standard IO to a TUN device on the remote end.&lt;/p&gt;

&lt;p&gt;The below command will setup the 192.168.32.2 address on localhost to communicate with 192.168.32.1 on the server host over a VPN. If you use the 192.168.32.1 address you should be able to connect to network services on the server as though it was on the LAN.&lt;/p&gt;

&lt;p&gt;The first location just sets up a local TUN device with an address and brings the network interface up. The second location will ssh into the server machine and run socat there to connect the standard IO of the ssh session to a TUN device on the server. The -d -d options can be selectively removed to remove the debugging chatter from the local and remote socat processes but are very informative when experimenting.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# socat -d -d  \
    TUN:192.168.32.2/24,up \
    SYSTEM:&quot;ssh root@server socat -d -d  - 'TUN:192.168.32.1/24,up'&quot; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You might need to be root to create TUN devices. If socat can not make them as the current user you will see a message like the below.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;2009/04/23 14:41:09 socat[17930] E ioctl(3, TUNSETIFF, {&quot;&quot;}: Operation not permitted
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;socat is a great tool to have in your collective command line toolbox. There are options to use socat with tcpwrappers, and a huge array of the parameters that can be set on sockets and other through other low level system calls can be tweaked through parameters to socat.&lt;/p&gt;

&lt;p&gt;The ability to setup a makeshift VPN using ssh for data protection using a one line command could be just what you are after when you want to get at a few services without needing to research which ports you need to forward.&lt;/p&gt;</content><author><name></name></author><summary type="html">The socat command shuffles data between two locations. One way to think of socat is as the cat command which transfers data between two locations rather than from a file to standard output. I say that socat works on two locations rather than two files because you can grab data from a network socket, named pipe, or even setup a general virtual network interface as one end point.</summary></entry></feed>