Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Friday, September 12, 2025

Hello world assembly on x86 Linux

Hello world assembly on x86 Linux

Save code below as hello.asm
global _start

section .data
message: db 'hello, world!', 10

section .text
_start:
    mov     rax, 1          ; system call number should be stored in rax
    mov     rdi, 1          ; argument #1 in rdi, where to write (description)?
    mov     rsi, message    ; argument #2 in rsi, where does the string start?
    mov     rdx, 14         ; argument #3 in rdx, how many bytes to write?
    syscall                 ; this instruction invokes a system call

    mov     rax, 60         ; 'exit' syscall number
    xor     rdi, rdi
    syscall
Now assemble/build the file
nasm -felf64 hello.asm -o hello.o
Link to create executable
ld -o hello hello.o
Run it
u1@v1vm10:~$ ./hello 
hello, world!

Sunday, April 09, 2023

Kali Linux (2023.1) randomly freezes on Dell Latitude 7490

Kali Linux(2023.1) randomly hard freezes on Dell Latitude 7490. This can happen immediately or after few minutes.

This is  likely caused by a bug in integrated Intel GPU (i915) driver, see the following links for more information:

Bug 102586 - System freeze with Kernels > 4.11.x (freeze on 4.12.x and 4.13.x) 

Fix for Intel i915 GPU Freeze on Recent Linux Kernels

Linux 5.x random kernel panic workaround

Workaround:

  1. Touch /etc/modprobe.d/i915.conf
  2. Add this line
    options i915 enable_psr=0
  3. Reboot

//end

Sunday, May 16, 2021

Reverse SSH shell to WSL2

Reverse SSH shell to WSL2

WLS2 is configured by default in a NAT network.That means we can't generally reach it from the outside. 

To connect to it externally, let us configure WSL 2 for reverse shell

Prerequisite

  • Another SSH server that acts as gateway. This server should be accessible from the outside. For this exercise we will be using 192.168.2.30 as the gateway IP.

Step 1: Enable SSH on WSL2

$: sudo ssh-keygen -A
Then start SSH:
$: sudo service ssh start

Step 2: Verify connection from WSL2 to the gateway SSH server

$: ssh -R 2222:localhost:22 u1@192.168.2.30
Below is an example connection to Kali SSH server
From Kali gateway server, verify that we can connect to port 2222, like:
$: ssh u2@localhost -p 2222
By default WSL2 does not allow SSH connection using password, you will get an error like below.
u2@localhost: Permission denied (publickey).

To fix this, change /etc/ssh/sshd_config on WSL2, ensure that: 

  • PasswordAuthentication is set to yes
  • ChallengeResponseAuthentication is set to no
And restart SSH, like so:
$: sudo service ssh restart
Let us try to open the tunnel again, on WSL2 run:
$: ssh -R 2222:localhost:22 u1@192.168.2.30
Now go back to the gateway server and do:
$: ssh u2@localhost -p 2222
You should now be able to connect to the WSL2 from the gateway like below

Step 3: Use public/private key to connect

Providing the password everytime we establish a connection gets really tiring, so let us use public/private key for the connection.
Let us start from WSL2 to the gateway, generate private/public key pair on WSL2:
$: ssh-keygen -t rsa -b 2048
Then copy id_rsa.pub to the gateway, like:
$: cat ~/.ssh/id_rsa.pub | ssh u1@192.168.2.30 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Now, if you re-run the command to create a tunnel, it should just connect without asking for password, like:
$: ssh -R 2222:localhost:22 u1@192.168.2.30
Next up is connection from the gateway to WSL2. Let us generate private/public key on the gateway, like:
$: ssh-keygen -t rsa -b 2048
Then copy id_rsa.pub to the WSL2, like:
$: cat ~/.ssh/id_rsa.pub | ssh u2@localhost -p 2222 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Now we are making progress.

Step 4: Create the tunnel when WSL2 is started

It is probably best for the tunnel that was created to require no interaction, so we run it like:
$: ssh -R 2222:localhost:22 u1@192.168.2.30 -N
Or better yet, run it in a background
$: ssh -R 2222:localhost:22 u1@192.168.2.30 -N &
Now to invoke this on WSL start, we need to ensure that SSH server is started and then create the tunnel. We don't want sudo to ask for the password when starting the service, so let us allow running sudo without password for the default account (u2).
$: sudo visudo
Then add the following:
u2 ALL=(ALL) NOPASSWD: ALL
Do save and exit in Nano (Ctrl+S followed by Ctrl+X).
Then add the following to ~/.bashrc, do this towards the end of the file:
sudo service ssh status
if [ $? -ne 0 ]; then
  echo "Starting"
  sudo service ssh start
  echo "tunnel"
  nohup ssh -R 2222:localhost:22 u1@192.168.2.30 -N >/dev/null 2>&1 &
fi

Step 5: Connect to WSL2 via the gateway

Now for the fun stuff, to connect to WSL2 from getaway, we need to create another tunnel!!! This time ssh client will listen on port 2222 locally, any connection to that port will be tunneled to the gateway (192.168.2.30) on port 2222. Remember that port 2222 on the gateway was reverse tunnelled to port 22 on WSL2:
c:\> ssh -L 2222:localhost:2222 u1@192.168.2.30
So to finally connect to WSL2, do:
c:\> ssh u2@localhost -p 2222

Fix corrupted console font on Kali Linux 2021.1

Fix corrupted console font on Kali Linux 2021.1
I have installed Kali Linux on a VM with 512 MB memory and 2 vCPU using network installer. The installation was uneventful but my first login shows the following:
It is not pretty, so to fix it do:
$: sudo dpkg-reconfigure console-setup

Then select:

  • UTF-8
  • Guess optimal character set
  • Terminus
  • 8x16

Select different font type as appropriate.

It should now look much better

Keywords: Kali, Linux, Console, garbled, corrupted, text

Saturday, March 14, 2020

Fatal: Cannot find FastHTMLParser used by Clipbrd of package LCLBase

I have tried to install Lazarus 2.0.0 (FPC 3.0.4) on MX Linux 19.1 but got the following error message when compiling the default project created by Lazarus.

Fatal: Cannot find FastHTMLParser used by Clipbrd of package LCLBase.

One way to fix this is to install the fpc package, like:
$: sudo apt install fpc

Keywords: Free Pascal, Lazarus

Wednesday, January 29, 2020

mrxvt settings that I like

mrxvt is a tabbed VT102 terminal emulator for X Window System. This is like gnome-terminal(GNOME) or konsole(KDE). The good thing with mrxvt is that it is light-weight so this is good for old machine when combined with lighter window managers like fluxbox when running in graphical mode. Below is my .mrxvtrc configuration suites my taste:

Or download this configuration. ~yth~

Saturday, January 25, 2020

How to get GNOME version from the command line

Get Gnome version from terminal
$: gnome-shell --version

Alternative ways to get version, works on older versions of Gnome.

$: gnome-about --version

This will show something like:
GNOME gnome-about 2.32.0

This can also be done using the command below.
$: gnome-session --version
Above command does not work on Fedora 22 Workstation.

Tags:
GNOME version command line cli

Sunday, June 17, 2018

VirtualBox Shared Clipboard not working on Ubuntu Budgie 18.04 VM guest

VirtualBox Guest Additions are installed and Shared Clipboard (Bidirectional) option selected. Even tried to reboot still not working. Any hints how to fix is appreciated. Note that Ubuntu 18.04 (Gnome) and Ubuntu 18.10 LXQt is working the same Windows 10 host.

[6/18/2018] Most be getting old. I assumed VirtualBox guest additions was installed as the VM window can be resized. Anyway, installed guest additions and copy/paste worked like a charm.

Also reported in Discource
https://discourse.ubuntubudgie.org/t/virtualbox-shared-clipboard-not-working-on-budgie-18-04/646

Monday, March 21, 2016

View library dependencies in Linux

I was trying to get Squeak VM 5.0 running on Ubuntu 16.04 beta 1 and got the following:

/home/timus/Downloads/Squeak-5.0-All-in-One/Squeak-5.0-All-in-One.app/Contents/LinuxAndWindows/Linux-i686/bin/squeak
could not find display driver vm-display-X11; either:
  - check that /home/timus/Downloads/Squeak-5.0-All-in-One/Squeak-5.0-All-in-One.app/Contents/LinuxAndWindows/Linux-i686/lib/squeak/5.0-3397//vm-display-X11.so exists, or
  - use the '-plugins <path>' option to tell me where it is, or
  - remove DISPLAY from your environment.
./squeak.sh: line 1:  8289 Aborted                 (core dumped) ./Squeak-5.0-All-in-One.app/Contents/LinuxAndWindows/squeak.sh

To view library dependencies in Linux, do:
$: ldd Squeak-5.0-All-in-One.app/Contents/LinuxAndWindows/Linux-i686/lib/squeak/5.0-3397/vm-display-X11

This should display library dependencies of vm-display-X11.

Friday, January 22, 2016

The type or namespace name `Gtk' could not be found. Are you missing an assembly reference?

After fixing items below related to MonoDevelop on Linux Mint 7.3, another error shows up:
http://8thstring.blogspot.com/2016/01/monodevelop-does-not-start-on-linux.html
http://8thstring.blogspot.com/2016/01/could-not-obtain-c-compiler-c-compiler.html

The type or namespace name `Gtk' could not be found. Are you missing an assembly reference?

To fix install gtk-sharp-2.0 libraries, like:
$: sudo apt-get install gtk-sharp2


Thursday, January 21, 2016

Could not obtain a C# compiler. C# compiler not found for Mono / .Net 4.0

Tried to build a monodevelop project in Linux Mint 17.3 but got the following error message

Could not obtain a C# compiler. C# compiler not found for Mono / .Net 4.0
To fix this do:
$: sudo apt-get install mono-gmcs

Reference(s):
http://stackoverflow.com/questions/8022653/c-sharp-compiler-not-found-when-building-a-package-monodevelop-linux

Monodevelop does not start on Linux Mint 7.3

This is issue is similar to this one but different dependencies. So, I have installed monodevelop like:
$: sudo apt-get install monodevelop
Unfortunately it is not working. Need to install the following dependencies to make it to work
$: sudo apt-get install libmono-cairo2.0-cil

Sunday, November 02, 2014

Updating packages on OpenSUSE via console

Zypper is the functionally equivalent to apt-get or aptitude for OpenSUSE. Man page should give you more information how to use it, you can also visit http://en.opensuse.org/SDB:Zypper_usage_1 for additional information.

For example, to update your current system with the latest packages open konsole and do:

$: su
#: zypper refresh
#: zypper update

To install plain old rpm do:
$: su
#: zypper install google-chrome-stable_current_i386.rpm
This should install the downloaded stable version of Google Chrome. Of course you can substitute suitable rpm as necessary.

To search for a package like libpng, do:
$: zypper search libpng

~ts

The following add-ins could not be started MonoDevelop.GnomePlatform

Installing MonoDevelop in OpenSUSE 12.2 from its repository was very easy. When running it for the first time though I got the message:
The following add-ins could not be started:
The root of the trace shows
MonoDevelop.GnomePlatform,2.8
A quick search shows that MonoDevelop depends on libgnomeui. This should have been part of dependencies when installing the application but well....

Below is the screen shot of the error message.
References:
http://software.1713.n2.nabble.com/MonoDevelop-and-openSUSE-12-1-td7462957.html

[2013/04/09] - Same issue observed in OpenSUSE 12.3 and also the same fix.
[2014/11/02] - Same issue observed in OpenSUSE 13.3, mondevelop 3.0.6 and the same fix.

Saturday, March 22, 2014

Extracting tar.gz file into specific folder

For example, to extract pycharm-community-3.1.1.tar.gz to ~/bin folder do:
$: tar -xvzf pycharm-community-3.1.1.tar.gz -C ~/bin

Friday, November 01, 2013

Mounting Samba share in Windows 7 yields System error 58 has occured

Got a Windows 7 SP1 32-bit Pro machine that have seen various large applications already. So I am not sure if the security policy of the machine is the default. When trying to mount a Samba share got the error message below.
System error 58 has occurred.

The specified server cannot perform the requested operation.

This was done via net use \\<ip>\share. Mounting the share via Windows Explorer yields nothing, just a long wait for nothing.

The fix for my case was to change Security Settings | Local Policies | Security Options | Microsoft network client: Digitally sign communications (always) to disabled. You have to reboot the machine for the changes to take effect.

References:
http://social.technet.microsoft.com/Forums/windows/en-US/5dd9991b-78e7-4fa3-b17c-366e4ae0092f/cant-connect-to-samba-from-windows-7-vista-xp-ok-many-popular-solutions-tried-without-success?forum=w7itpronetworking


Friday, August 16, 2013

Mounting a Windows share using smbfs with read-write access

To mount a Windows share using smbfs do the following:
#: mount -t cifs -o username=your_user_name,uid=1000 //machine_name/share_name /mnt/point
Or the old style:
#: mount -t smbfs -o username=your_user_name,uid=1000 //machine_name/share_name /mnt/point
Note here that uid=1000 is not a magic number but rather your linux userid. You can get this value from passwd file normally located in /etc/passwd. The user with uid=1000 should be able to manipulate files pointed to by //machine_name/share.
And when connecting to a share that is mananged by Active Directory, need to escape the backslash for it to work, e.g.:
#: mount -t smbfs -o username=domain-name\\username,uid=1000 //machine_name/share_name /mnt/point

Notes:
Need to install smbfs for this to work, like (Debian/Ubuntu):
#: sudo apt-get install cifs-utils

~ts~

Saturday, January 19, 2013

Installing Google Chrome in Ubuntu 12.10 from the command line

Of course you can install Chromium, but hey I wanna use Google Chrome. To install from the command line, do:
$: cd ~/Downloads
$: wget https://dl.google.com/linux/direct/google-chrome-stable_current_i386.deb
$: sudo dpkg -i ~/Downloads/google-chrome-stable_current_i386.deb
$: sudo apt-get -f install

The last line is needed to install the required dependencies and complete Chrome installation.
To install 64bit version of Chrome, you have to change download path to https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb, like:

$: wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

Note(s):
* This applies to Debian 7 Wheezy

Reference(s):
http://askubuntu.com/questions/79280/how-to-install-chrome-browser-properly-via-command-line

Saturday, December 01, 2012

How to detect if reboot is required after running apt upgrade

So you have a Debian based installation (i.e., Ubuntu, Linux Mint and of course Debian itself), how would you know if you need to reboot after running apt-get upgrade?

Well, this should be as easy as checking for the presence of the file /var/run/reboot-required

Tags:
apt, apt-get, upgrade, reboot, required

References:
http://askubuntu.com/questions/28530/how-can-i-tell-what-package-requires-a-reboot-of-my-system
http://serverfault.com/questions/92932/how-does-ubuntu-keep-track-of-the-system-restart-required-flag-in-motd


Sunday, November 25, 2012

Get CPU information in Ubuntu from command line

Method 1: Using lshw

$: sudo lswh -class cpu

This will show something like:
  *-cpu                   
       description: CPU
       product: Intel(R) Pentium(R) M processor 2.13GHz
       vendor: Intel Corp.
       physical id: 400
       bus info: cpu@0
       version: 6.13.8
       slot: Microprocessor
       size: 2133MHz
       capacity: 2133MHz
       width: 32 bits
       clock: 133MHz
       capabilities: fpu fpu_exception wp vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov clflush dts acpi mmx fxsr sse sse2 ss tm pbe nx up bts est tm2 cpufreq

Method 2. Using special /proc, like:
$: cat /proc/cpuinfo

processor      : 0
vendor_id      : GenuineIntel
cpu family     : 6
model          : 13
model name     : Intel(R) Pentium(R) M processor 2.13GHz
stepping       : 8
microcode      : 0x20
cpu MHz        : 800.000
cache size     : 2048 KB
fdiv_bug       : no
hlt_bug        : no
f00f_bug       : no
coma_bug       : no
fpu            : yes
fpu_exception  : yes
cpuid level    : 2
wp             : yes
flags          : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov clflush dts acpi mmx fxsr sse sse2 ss tm pbe nx up bts est tm2
bogomips       : 1596.16
clflush size   : 64
cache_alignment: 64
address sizes  : 32 bits physical, 32 bits virtual
power management:

CPP Quick Guide

Basics Hello world User input While loop If statement For loop Switch statement Read file using ifstream Write to a file using ofstr...