For this tutorial, we’ll be using Samba. As for what Samba really is though, the most I can figure out from my search on Google is that Samba is a free and open-source software that allows files to be shared across Windows and Linux systems simply and easily. To be exact, it is an open-source implementation of the SMB/CIFS protocol.
Setup
Install smbclient util with pacman
1
sudo pacman -S smbclient
Create shared directory
1
sudomkdir /home/<user>/share
This directory is to be shared between the host and guest machines.
Edit the Samba configuration file
Open up the configuration file for samba:
1
sudo nano /etc/samba/smb.conf
Add these lines to the configuration file:
1 2 3 4
[share] path = /home/<user>/share read only = no guest ok = yes
Create Samba password
1
sudo smbpasswd -a <user>
Restart the Samba service to refresh:
1
sudo systemctl restart smb.service
IP Configuration
In the UTM app on your MacBook, go to the settings for the ArchLinux VM and enable the “Port Forwarding” option. Add a new rule with the following settings:
Protocol: TCP
Host Port: 445
Guest IP: IP address of the ArchLinux VM
Guest Port: 445
To get Guest IP, run the following line:
1
[root@alarm ~]# ip addr | grep inet
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
inet 192.168.65.3/24 metric 1024 brd 192.168.65.255 scope global dynamic enp0s1
inet6 fde3:e977:b4d3:5c13:e0b4:51ff:fee5:2142/64 scope global dynamic mngtmpaddr noprefixroute
inet6 fe80::e0b4:51ff:fee5:2142/64 scope link
In this case, it’s 192.168.65.3.
To get Host IP, run the following line:
1 2 3
ipconfig getifaddr en0
# 10.8.189.52
On your MacBook, open Finder and click “Go” > “Connect to Server” (Cmd + K).
Enter this address: smb://localhost:445/share
Enter the Samba username and password when prompted.
You can now access the shared directory and transfer files between the host and guest operating systems.
Mount /mnt/share
Normally during the boot-up process of our machines, the mounting up of disks and folders are done for us. However, I keep getting this error telling me:
[FAILED] Failed to mount /mnt/share.
So I have to mount this directory myself, by running:
1
sudo mount -t cifs //localhost/share /mnt/share -o user=<Samba username>,password=<Samba password>
This command mounts a Samba share located on the local machine (localhost) to a directory (/mnt/share) using the Common Internet File System (CIFS) protocol.
The -o option specifies additional mount options, in this case, it provides the Samba username and password to authenticate and access the share.
Enable Samba service
But before we run this command, we have to ensure that Samba service on the ArchLinux VM is up and running.
Check that the Samba service is running on the ArchLinux VM:
1
sudo systemctl status smb.service
If the service is not running, start it using the following command:
1
sudo systemctl start smb.service
To automatically start the Samba service on boot, you can enable the smb.service unit running the following command:
1
sudo systemctl enable smb.service
Make sure that the Samba username and password are correct.
1
smbclient //localhost/share -U mccranky
Restart the ArchLinux VM to test that the Samba service starts automatically:
1
sudo systemctl reboot
To check whether /mnt/share has been successfully mounted, run the following line:
1
mount | grep /mnt/share
If the directory is mounted, we should be able to see something similar to this:
//localhost/share on /mnt/share type cifs (rw,relatime,vers=3.1.1,cache=strict,username=mccranky,
uid=0,noforceuid,gid=0,noforcegid,addr=127.0.0.1,file_mode=0755,dir_mode=0755,soft,nounix,serveri
no,mapposix,rsize=4194304,wsize=4194304,bsize=1048576,echo_interval=60,actimeo=1,closetimeo=1,use
r=mccranky)
Mount /mnt/share on startup
To automatically mount the Samba shared directory on boot, you can add an entry to the /etc/fstab file.
1
sudo nano /etc/fstab
Then append the following line to the end of the file:
However, it seems that our new input comflicts with this line:
1
share /mnt/share 9p trans=virtio,nofail 0 0
The reason for this is because our new line mounts a CIFS file system from localhost onto the mount point /mnt/share, using the username mccranky and password Rogue12.
The old line mounts a 9p file system onto the same mount point /mnt/share, using the virtio transport and the nofail option.
Since our old entry gave us much headache, I’ll just swap it for the new one. :)
Let’s test the mount by running the following command:
1
sudo mount -a
This command will attempt to mount all entries in the /etc/fstab file. If there are any errors, it will display them in the terminal.
Now we run sudo systemctl reboot to see if everything has been resolved at boot-up. There should be no more failures.
ArchLinux is a text-based operating system that does not come with a graphical interface, and all tasks are performed by running commands in the Command Line Interface (CLI).
Setup
The setting up of UTM and running virtual machines on it is rather simple. Just follow the steps shown below and you’ll be playing around soon enough.
Click on Open in UTM - this automatically redirects you to your newly installed UTM app, where UTM will download the pre-built ArchLinux VM for you.
(Optional) You can run the VM as is, but feel free to tweak with the settings if you want to.
Install Dependencies
sudo
1 2 3 4 5 6
su -
pacman -Syu
pacman -S sudo
su is short for “substitute user”, and it is used to switch to another user account in Unix-based operating systems. When you use su without any options, it will switch to the root user account by default.
The - option used with su is used to simulate a full login for the new user, and it is not specific to the root user. When you use su - followed by a username, it will switch to that user’s account with a login shell.
So, to summarize:
su is used to switch to another user account.
su without any options will switch to the root user account by default.
su - followed by a username will switch to that user’s account with a login shell, simulating a full login for that user.
pacman
pacman is the package manager for Arch Linux, a lightweight and flexible Linux distribution.
With pacman, users can easily install, remove, and update software packages on their Arch Linux system. It uses a binary package format, which means that packages are precompiled and ready to install, making the process faster and more efficient than compiling from source.
Some common pacman options include:
pacman -Syu: -S stands for “sync”, -y and -u are options that tell pacman to refresh the package databases and upgrade all packages, respectively. -Syu, as a whole, updates the system and all installed packages to the latest version.
pacman -S <package>: -S is a shorthand for --sync. This command installs a package. When --needed option is specified alongside the pacman -S command, only packages that are not already installed on your system get installed.
pacman -R <package>: -R stands for “remove”. This command removes a package.
pacman -Ss <searchterm>: -Ss stands for “synchronize/search”. This command searches for packages containing the specified search term.
pacman -Q: -Q stands for “query”. This command lists all installed packages on the system.
Use the following commands with caution!
pacman -Sc: Removes all the packages from the cache which are not currently installed on the system. It will only remove packages that are not needed anymore and will not affect any installed packages. This command can be useful to free up disk space on the system.
pacman -Scc: Removes all the packages from the cache, including those that are currently installed on the system. It will remove all the package files from the cache, along with their associated databases. This command can be useful if you want to completely clean the package cache and start fresh.
pacman -Syy: Forces a refresh of all package databases, even if they are already up to date. This ensures that you have the latest package database information available, which can be useful in situations where the package databases may have become out of sync or corrupted.
Once the installation is complete, we need to configure sudo to allow users to execute commands with administrative privileges. To do this, you need to add the user to the wheel group. Run the following command to add the user to the wheel group:
1
usermod -aG wheel <username>
This command is used to add a user to the wheel group, which will give them the ability to perform administrative tasks on the system using the sudo command.
usermod: This is a command-line utility in Unix-based operating systems that is used to modify user account properties. The usermod command allows you to add or remove a user from a group, change a user’s home directory, and modify other user account settings.
wheel: This is a special group in Unix-based operating systems that is used to control access to administrative tasks. Users who are members of the wheel group are allowed to use the sudo command to execute commands with root privileges.
-aG: These two options used alongside usermod are used to add a user to a group. Specifically, -a stands for “append”, which means that the user is added to the group without removing them from any other groups they may already be a member of. -G stands for “group”, and is followed by the name of the group to add the user to.
1
visudo -f /etc/sudoers
visudo: This is a command used in Unix-based operating systems to edit the sudoers file, which controls user access to administrative commands.
-f: This option is used to specify the file to edit.
visudo uses the system’s default editor to open and edit the sudoers file, which is often vi.
If vi is not your thing, you can always specify which editor to use by pass EDITOR=<editor-name> in front of visudo. You can change the default editor once and for all by change these two environment variables: VISUAL and EDITOR.
1
export EDITOR=nano
Note The main difference between the two is that VISUAL is used for visual editors, such as Sublime Text, Atom, or Visual Studio Code, while EDITOR is used for non-visual editors, such as nano, vim, or emacs.
Let’s add the finishing touch and uncomment the following line in the sudoers file:
1
%wheel ALL=(ALL:ALL) ALL
SPICE guest tools
SPICE stands for Simple Protocol for Independent Computing Environments. It is a remote computing solution that allows users to access the desktop of a virtual machine or remote system from a client device. SPICE provides a high-performance, low-latency connection that supports a wide range of features, including audio, video, and USB redirection. It is commonly used in virtualization environments, such as those provided by QEMU and KVM, to provide remote access to virtual machines.
However, we’re using it for clipboard sharing. With SPICE guest tools installed, the clipboard will be synced between the guest and the host.
Install the spice-vdagent package by running the following command:
1
sudo pacman -S spice-vdagent
Once the installation is complete, start the spice-vdagent service by running the following command:
1
sudo systemctl start spice-vdagentd.service
You can also enable the service to start automatically at boot time by running the following command:
1
sudo systemctl enable spice-vdagentd.service
However, I wasn’t able to enable it on first try.
The unit files have no installation config (WantedBy=, RequiredBy=, Also=,
Alias= settings in the [Install] section, and DefaultInstance= for template
units). This means they are not meant to be enabled or disabled using systemctl.
Possible reasons for having this kind of units are:
* A unit may be statically enabled by being symlinked from another unit's
.wants/ or .requires/ directory.
* A unit's purpose may be to act as a helper for some other unit which has
a requirement dependency on it.
* A unit may be started when needed via activation (socket, path, timer,
D-Bus, udev, scripted systemctl call, ...).
* In case of template units, the unit is meant to be enabled with some
instance name specified.
Here are some potential reasons why this error might be occurring and how we can address them:
The unit file might be missing the [Install] section. Check the spice-vdagentd.service file located in /usr/lib/systemd/system to see if it contains an [Install] section with the appropriate WantedBy or RequiredBy settings. If the section is missing or incomplete, you can add it manually. For example, to enable the service at boot time, you can add the line WantedBy=multi-user.target to the [Install] section.
The unit file might be a template unit. Template units are designed to be instantiated with specific instance names and cannot be enabled or disabled directly. Check the spice-vdagentd.service file to see if it contains the DefaultInstance setting in the [Install] section. If it does, you will need to specify an instance name when enabling the service using the systemctl enable command. For example, if the DefaultInstance setting is my-instance, you would run systemctl enable spice-vdagentd@my-instance.service.
The unit file might be symlinked from another unit’s .wants/ or .requires/ directory. Check the contents of these directories located in /etc/systemd/system to see if there are any symlinks pointing to spice-vdagentd.service. If there are, you do not need to enable the service separately as it will be started automatically when the dependent unit is started.
It’s the first fix for me. My [Install] section had only one line “Also=spice-vdagentd.socket“, so I added a second.
Install the git package by running the following command:
1
sudo pacman -S git
yay
The reason why we’re not installing apt is because apt is a package manager used in Debian-based Linux distributions like Ubuntu, and it is not available in Arch Linux. Instead, Arch Linux uses its own package manager called pacman, the one we just talked about.
If you are familiar with apt and want to use a similar package manager in Arch Linux, you can use yay, which is a popular AUR (Arch User Repository) helper that provides a pacman-like interface with added features.
1
sudo pacman -S base-devel
Install yay by running the following command:
1 2 3 4 5 6
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si
makepkg -si is a command used in Arch Linux to build and install a package from source code.
makepkg: This is a tool that automates the process of building packages from source code in Arch Linux. It creates a package file that can be installed using the package manager.
-s: A flag that tells makepkg to install any dependencies needed to build the package.
-i: A flag that tells makepkg to install the package after it has been built.
neovim
1
sudo pacman -S --needed neovim
Create a non-root user
Before we move on to the next step, we have to create an alternative user apart from our current root, otherwise makepkg -si won’t work.
It’s fairly simple.
To create a non-root user account on Arch Linux, we have to run these few steps:
Run the following command to create a new user account:
1
useradd -m -s /bin/bash <username>
Set a password for the new user account:
1
sudo passwd <username>
Add the new user to the wheel group to allow them to use sudo:
1
usermod -aG wheel <username>
At last, we simply log out of the root user account and log in to the new user account by entering the username and password we just created.
Once the installation is complete, you can use yay to search for and install packages from the AUR. For example, to install the firefox package from the AUR, you can run the following command:
1
yay -S firefox
Or if you want to uninstall, run the following command:
1
yay -Rns firefox
This command will remove Firefox and its dependencies (-R), including any configuration files (-n) and any packages that were installed as dependencies and are no longer required (-s).
Now, yay will automatically download and install the package and its dependencies.
Note While yay provides a pacman-like interface, it is not a drop-in replacement for apt, and there may be some differences in the way packages are managed and installed.
Refresh keys
PGP keys are used to verify the authenticity of packages in the official Arch Linux repositories.
Update the keyring package by running the following command:
1
sudo pacman -Sy archlinux-keyring
Import the new keys by running the following command:
1
sudo pacman-key --populate archlinux
Refresh the keyring by running the following command:
1 2 3
sudo pacman-key --refresh-keys
# This command retrieves the latest keys from the keyserver and update your keyring accordingly.
Now your keychains should be up to date and you should be able to verify the authenticity of packages in the official Arch Linux repositories.
Poweroff
Once you had your fun, you’d probably want to poweroff. Here’s what you should do:
Lately I’ve been thinking that since Java has an equalsIgnoreCase method, JavaScript must have something similar. This is what I found: the localeCompare method.
Structure
1
str1.localeCompare(str2, [locales], [options])
Note: The Linux commands also has a locale command!
Available locales
language
'en': English
'fr': French
'de': German
'es': Spanish
'ja': Japanese
'zh': Chinese
'ar': Arabic
'ru': Russian
We can also use a combination of language and region subtags to specify a more specific locale. For example:
'en-US': English (United States)
'fr-CA': French (Canada)
'de-DE': German (Germany)
'es-MX': Spanish (Mexico)
'ja-JP': Japanese (Japan)
'zh-CN': Chinese (China)
'ar-EG': Arabic (Egypt)
'ru-RU': Russian (Russia)
The caseFirst option in the localeCompare() method specifies whether uppercase letters should come before or after lowercase letters in the sort order. It can take one of the following two values:
upper: Sort uppercase letters before lowercase letters.
lower: Sort lowercase letters before uppercase letters.
[directory-path] is an optional argument that specifies the directory you want to display as a tree structure. If you don’t specify a directory path, tree will display the tree structure for the current directory.
Here are some useful options you can add to the tree command:
-L[level]: Limit the depth of the tree to [level] directories.
-I[pattern]: Exclude files and directories that match the [pattern].
-P[pattern]: [pattern] is used to match files or directories that you want to include in the output.
-a: Show hidden files and directories.
-f: Print the full path prefix for each file or directory.
-h: Print the size of each file or directory in a human-readable format.
Example
1 2 3 4 5 6
$ tree -L 1 -P "source/*" -I "_drafts|_pages"source
source └── _posts
2 directories, 0 files
You can omit the report on the last line with option --noreport if it bothers you.
$ telnet localhost 3025
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 /0:0:0:0:0:0:0:1 GreenMail SMTP Service v2.1.0-alpha-1 ready
421 Service shutting down and closing transmission channel (socket timeout, SO_TIMEOUT: 30000ms)
握手成功了!接下里可以输入四字指令和 SMTP 服务器交流:
C: HELO localhost
S: 250-/0:0:0:0:0:0:0:1
250 AUTH PLAIN LOGIN
C: MAIL FROM: <example@email.com>
S: 250 OK
C: RCPT TO: <example@email.com>
S: 250 OK
C: DATA
S: 354 Start mail input; end with <CRLF>.<CRLF>
C: HELLO THERE
THIS IS USER SPEAKING
.
S: 250 OK
C: QUIT
S: 221 /0:0:0:0:0:0:0:1 Service closing transmission channel
Connection closed by foreign host.
解释一下这些缩写是什么意思:
HELO: hello
RCPT: recipient
CRLF: carriage return & line feed
连接 IMAP 服务器
认证阶段
2023-10-09 14:59:25,387 INFO
user.UserManager| Created user login example@email.com for address example@email.com with password
example@email.com because it didn't exist before.
$ telnet localhost 3110
+OK POP3 server ready
user example@email.com
+OK
pass example@email.com
+OK user successfully logged on
交易阶段
C: list
S: 1 498
S: 2 912
S: .
C: retr 1
S: (blah blah ...
S: .................
S: ..........blah)
S: .
C: dele 1
C: retr 2
S: (blah blah ...
S: .................
S: ..........blah)
S: .
C: dele 2
C: quit
S: +OK POP3 server signing off
.: directory
./.bash_logout: ASCII text
./.bashrc: ASCII text
./bandit26.sshkey: PEM RSA private key
./.profile: ASCII text
./.pin: ASCII text, with no line terminators
./.bandit24.password: ASCII text
for i in {0000..9999}; do echo$i printf"%s %s\n""VAfGXJ1PBSsPSnvsjI8p759leLZ9GGar""$i" done
exit 0
除了语法上微小的一点差异,该题的syntax和C的语法很相像,所以不赘述了。
大致格式就是for [ test statement]; do <command>; done
编辑结束按ESC键回到普通模式,按:,然后输入指令wq,回车保存并退出。
执行script.sh,并把结果pipe到netcat:
1
./script.sh | nc localhost 30002 > output.txt
然后cat output.txt读取文本内容,这是其中的一小部分:
Fail! You did not supply enough data. Try again.
Wrong! Please enter the correct pincode. Try again.
Fail! You did not supply enough data. Try again.
Wrong! Please enter the correct pincode. Try again.
Fail! You did not supply enough data. Try again.
Wrong! Please enter the correct pincode. Try again.
Fail! You did not supply enough data. Try again.
Wrong! Please enter the correct pincode. Try again.
Fail! You did not supply enough data. Try again.
Wrong! Please enter the correct pincode. Try again.
Fail! You did not supply enough data. Try again.
Wrong! Please enter the correct pincode. Try again.
Fail! You did not supply enough data. Try again.
Wrong! Please enter the correct pincode. Try again.
Fail! You did not supply enough data. Try again.
Wrong! Please enter the correct pincode. Try again.
Fail! You did not supply enough data. Try again.
Correct!
The password of user bandit25 is p7TaowMYrmu23Ol8hiZh9UvD0O9hpx8d
Exiting.