Friday, December 18, 2020

Intento de accesos fallidos en SSHD

basado en 

https://blog.desdelinux.net/como-saber-que-intentos-fallidos-de-ssh-ha-tenido-nuestro-servidor/

https://www.jesusamieiro.com/ssh-ver-los-fallos-en-los-intentos-de-acceso-en-debian/


cat /var/log/auth* | grep Failed

cat /var/log/auth.log | grep Accepted*

Thursday, December 17, 2020

habilitar SSH 2FA de google

basado en: https://www.entredevyops.es/posts/ssh-2fa.html

 

sudo apt-get install -y libpam-google-authenticator

sudo nano /etc/pam.d/sshd

#y agregar auth required pam_google_authenticator.so

sudo nano /etc/ssh/sshd_config

ChallengeResponseAuthentication yes

sudo service sshd restart

#al usuario al cual le quieres activar el 2FA

google-authenticator


Tuesday, December 15, 2020

Enviar correo con adjunto en python

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
 
# Iniciamos los parámetros del script
remitente = 'Origen@gmail.com'
destinatarios = ['destinatarioseparadosPorcoma','dest2','dest3']
asunto = 'Correo de prueba'
cuerpo = 'Este es el contenido del mensaje'
ruta_adjunto = 'D:/Proyectos/Python/Archivo.xlsx'
nombre_adjunto = 'Archivo.xlsx'
 
# Creamos el objeto mensaje
mensaje = MIMEMultipart()
 
# Establecemos los atributos del mensaje
mensaje['From'] = 'origen@gmail.com'
mensaje['To'] = ", ".join(destinatarios)
mensaje['Subject'] = asunto
 
# Agregamos el cuerpo del mensaje como objeto MIME de tipo texto
mensaje.attach(MIMEText(cuerpo, 'plain'))
 
# Abrimos el archivo que vamos a adjuntar
archivo_adjunto = open(ruta_adjunto, 'rb')
 
# Creamos un objeto MIME base
adjunto_MIME = MIMEBase('application', 'octet-stream')
# Y le cargamos el archivo adjunto
adjunto_MIME.set_payload((archivo_adjunto).read())
# Codificamos el objeto en BASE64
encoders.encode_base64(adjunto_MIME)
# Agregamos una cabecera al objeto
adjunto_MIME.add_header('Content-Disposition', "attachment; filename= %s" % nombre_adjunto)
# Y finalmente lo agregamos al mensaje
mensaje.attach(adjunto_MIME)
 
# Creamos la conexión con el servidor
sesion_smtp = smtplib.SMTP('smtp.gmail.com', 587)
 
# Ciframos la conexión
sesion_smtp.starttls()
 
# Iniciamos sesión en el servidor
sesion_smtp.login('origen@gmail.com','ClaveSegura')
 
# Convertimos el objeto mensaje a texto
texto = mensaje.as_string()
 
# Enviamos el mensaje
sesion_smtp.sendmail(remitente, destinatarios, texto)
 
# Cerramos la conexión
sesion_smtp.quit()
 

basado en https://gist.github.com/2624789/d42aaa12bf3a36356342 

Friday, December 11, 2020

Enviar correo por PowerShell con archivo adjunto

recomiendo crear un archivo Ps1 ademas para llamarlo via cmd se debe agregar este codigo

powershell -ExecutionPolicy Bypass -File D:\Proyectos\correo.txt.ps1


Este es el contenido para el archivo PS1

$EmailTo = "CuentaDestino@gmail.com"  

$EmailFrom = "CuentaOrigen@gmail.com"  

$Emailuser = "username@gmail.com"  

$Emailpass = "XXXXXXXXX"  

$Subject = "Subject"  

$Body = "Test Body" 

$SMTPServer = "smtp.gmail.com" 

$filenameAndPath = "D:\BK\17-03-2019-archivos-bk.RAR"  

$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)

$attachment = New-Object System.Net.Mail.Attachment($filenameAndPath)

$SMTPMessage.Attachments.Add($attachment)

$SMTPClient = New-Object System.Net.Mail.SmtpClient($SMTPServer, 587);

$SMTPClient.EnableSSL = $true

$SMTPClient.credentials = New-Object System.Net.NetworkCredential($Emailuser, $Emailpass);

$SMTPClient.Send($SMTPMessage)


Wednesday, November 25, 2020

Dejar base de datos en modo single user

dejar base de datos en modo single user

 USE master;

GO

ALTER DATABASE AdventureWorks2012

SET SINGLE_USER

WITH ROLLBACK IMMEDIATE;

GO

ALTER DATABASE AdventureWorks2012

SET READ_ONLY;

GO

ALTER DATABASE AdventureWorks2012

SET MULTI_USER;

GO

The transaction log for database 'AdventureWorks2012' is full due to 'LOG_BACKUP' - log full

log full dejar en modo single 


ALTER DATABASE AdventureWorks2012  SET RECOVERY SIMPLE

GO




Thursday, November 19, 2020

Reset Onedrive - Reiniciar Onedrive

 

In the Run window, enter: 

Copy and paste

%localappdata%\Microsoft\OneDrive\onedrive.exe /reset

Click OK.

 

Wait 1 minute and then execute the following command:

 

Copy and paste

%localappdata%\Microsoft\OneDrive\onedrive.exe /update

Click OK.

 

If the OneDrive icon doesn’t re-appear after a few minutes, open the Run window again and enter:

Copy and paste

%localappdata%\Microsoft\OneDrive\onedrive.exe

Click OK.

 

I look forward to hearing from you.