Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (4 votes)
170 views

Download Complete Python Penetration Testing Essentials Techniques for ethical hacking with Python 2nd Edition Mohit PDF for All Chapters

hacking

Uploaded by

siozouryohei
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
170 views

Download Complete Python Penetration Testing Essentials Techniques for ethical hacking with Python 2nd Edition Mohit PDF for All Chapters

hacking

Uploaded by

siozouryohei
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Get ebook downloads in full at ebookmeta.

com

Python Penetration Testing Essentials Techniques


for ethical hacking with Python 2nd Edition Mohit

https://ebookmeta.com/product/python-penetration-testing-
essentials-techniques-for-ethical-hacking-with-python-2nd-
edition-mohit/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://ebookmeta.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Beginning Ethical Hacking with Python 1st Edition Sanjib


Sinha

https://ebookmeta.com/product/beginning-ethical-hacking-with-
python-1st-edition-sanjib-sinha/

ebookmeta.com

Learning Kali Linux Security Testing Penetration Testing


and Ethical Hacking 1st Edition Ric Messier

https://ebookmeta.com/product/learning-kali-linux-security-testing-
penetration-testing-and-ethical-hacking-1st-edition-ric-messier/

ebookmeta.com

Learning Kali Linux: Security Testing, Penetration


Testing, and Ethical Hacking, 2nd Edition - First Early
Release Ric Messier
https://ebookmeta.com/product/learning-kali-linux-security-testing-
penetration-testing-and-ethical-hacking-2nd-edition-first-early-
release-ric-messier/
ebookmeta.com

Mayor of Elf Town 4 1st Edition Dante King

https://ebookmeta.com/product/mayor-of-elf-town-4-1st-edition-dante-
king-2/

ebookmeta.com
Theatre Translation: A Practice as Research Model 1st
Edition Angela Tiziana Tarantini

https://ebookmeta.com/product/theatre-translation-a-practice-as-
research-model-1st-edition-angela-tiziana-tarantini/

ebookmeta.com

Essential Revision Notes for FRCS Urol Book 1 1st Edition


Jack Donati Bourne

https://ebookmeta.com/product/essential-revision-notes-for-frcs-urol-
book-1-1st-edition-jack-donati-bourne/

ebookmeta.com

Eyewitness to Chaos Personal Accounts of the Intervention


in Haiti 1994 1st Edition Walter E Kretchik

https://ebookmeta.com/product/eyewitness-to-chaos-personal-accounts-
of-the-intervention-in-haiti-1994-1st-edition-walter-e-kretchik/

ebookmeta.com

The Blobfish Book Jessica Olien

https://ebookmeta.com/product/the-blobfish-book-jessica-olien/

ebookmeta.com

Spoon Feeding Basic must Know Physics for Boys and Men for
IIT JEE Olympiad kind of exams by Professor Subhashish
Chattopadhyay 1st Edition Professor Subhashish
Chattopadhyay
https://ebookmeta.com/product/spoon-feeding-basic-must-know-physics-
for-boys-and-men-for-iit-jee-olympiad-kind-of-exams-by-professor-
subhashish-chattopadhyay-1st-edition-professor-subhashish-
chattopadhyay/
ebookmeta.com
College Reunions and Clues Tiffany Black Travel Cozy
Mystery 4 A.R. Winters Et El

https://ebookmeta.com/product/college-reunions-and-clues-tiffany-
black-travel-cozy-mystery-4-a-r-winters-et-el/

ebookmeta.com
||||||||||||||||||||

||||||||||||||||||||
||||||||||||||||||||

Python Penetration Testing


Essentials
Second Edition

5FDIOJRVFTGPSFUIJDBMIBDLJOHXJUI1ZUIPO

Mohit

BIRMINGHAM - MUMBAI

||||||||||||||||||||
||||||||||||||||||||

Python Penetration Testing Essentials


Second Edition
Copyright a 2018 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form
or by any means, without the prior written permission of the publisher, except in the case of brief quotations
embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented.
However, the information contained in this book is sold without warranty, either express or implied. Neither the
author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to
have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products
mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy
of this information.

Commissioning Editor: Vijin Boricha


Acquisition Editor: Noyonika Das
Content Development Editor: Roshan Kumar
Technical Editor: Sushmeeta Jena
Copy Editor: Safis Editing
Project Coordinator: Hardik Bhinde
Proofreader: Safis Editing
Indexer: Aishwarya Gangawane
Graphics: Jason Monteiro
Production Coordinator: Deepika Naik

First published: January 2015


Second edition: May 2018

Production reference: 1290518

Published by Packt Publishing Ltd.


Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.

ISBN 978-1-78913-896-2

XXXQBDLUQVCDPN

||||||||||||||||||||
||||||||||||||||||||

NBQUJP

Mapt is an online digital library that gives you full access to over 5,000 books and videos, as
well as industry leading tools to help you plan your personal development and advance
your career. For more information, please visit our website.

Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos
from over 4,000 industry professionals

Improve your learning with Skill Plans built especially for you

Get a free eBook or video every month

Mapt is fully searchable

Copy and paste, print, and bookmark content

PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and
ePub files available? You can upgrade to the eBook version at XXX1BDLU1VCDPN and as a
print book customer, you are entitled to a discount on the eBook copy. Get in touch with us
at TFSWJDF!QBDLUQVCDPN for more details.

At XXX1BDLU1VCDPN, you can also read a collection of free technical articles, sign up for a
range of free newsletters, and receive exclusive discounts and offers on Packt books and
eBooks.

||||||||||||||||||||
||||||||||||||||||||

Contributors

About the author


Mohit is a Python programmer with a keen interest in the field of information security. He
has B.Tech (UIET, KUK, 2009) and M.E (Thapar University, 2012) degree. He is a CEH,
ECSA at EC-Council USA. He has worked in IBM and Sapient. He is currently doing PhD
from Thapar Institute of Engg & Technology under Dr. Maninder Singh. He has published
several articles in national and international magazines. He is the author of Python
Penetration Testing Essentials, Python: Penetration Testing for Developers and Learn Python in 7
Days also by Packt. His username is mohitrajcs on gmail. .

||||||||||||||||||||
||||||||||||||||||||

About the reviewers


Sanjeev Jaiswal is a computer graduate from CUSAT with 9 years of industrial experience.
He uses Perl, Python, AWS, and GNU/Linux for his day-to-day activities. He's currently
working on projects involving penetration testing, source code review, security design, and
implementations in AWS and Cloud security projects.

He is learning DevSecOps and security automation currently as well. Sanjeev loves


teaching engineering students and IT professionals. He has been teaching for the past 8
years in his leisure time. He founded Alien Coders and Cybercloud Guru as well.

My special thanks to my wife, Shalini Jaiswal, for her unconditional support, and my
friends Ranjan, Ritesh, Mickey, Vivek, Hari, Sujay, Shankar, and Santosh for their care
and support all the time.

Rejah Rehim is currently the Director and Chief Information Security Officer (CISO) of
Appfabs. Previously holding the title of Security Architect at FAYA India, he is a long-time
preacher of open source and steady contributor to the Mozilla Foundation. He has
successfully created the world's first security testing browser bundle, PenQ, an open
source Linux-based penetration testing browser bundle preconfigured with tools
for security testing. He is also an active member of OWASP and the chapter
leader of OWASP Kerala. Additionally, Rejah also holds the title of commander at
Cyberdome, an initiative of the Kerala Police Department.

Packt is searching for authors like you


If you're interested in becoming an author for Packt, please visit BVUIPSTQBDLUQVCDPN
and apply today. We have worked with thousands of developers and tech professionals,
just like you, to help them share their insight with the global tech community. You can
make a general application, apply for a specific hot topic that we are recruiting an author
for, or submit your own idea.

||||||||||||||||||||
||||||||||||||||||||

Table of Contents
Preface 1
Chapter 1: Python with Penetration Testing and Networking 6
Introducing the scope of pentesting 7
The need for pentesting 7
Components to be tested 8
Qualities of a good pentester 8
Defining the scope of pentesting 9
Approaches to pentesting 9
Introducing Python scripting 10
Understanding the tests and tools you'll need 11
Learning the common testing platforms with Python 11
Network sockets 11
Server socket methods 12
Client socket methods 13
General socket methods 13
Moving on to the practical 14
Socket exceptions 22
Useful socket methods 23
Summary 29
Chapter 2: Scanning Pentesting 30
How to check live systems in a network and the concept of a live
system 31
Ping sweep 31
The TCP scan concept and its implementation using a Python script 35
How to create an efficient IP scanner in Windows 37
How to create an efficient IP scanner in Linux 44
The concept of the Linux-based IP scanner 44
nmap with Python 47
What are the services running on the target machine? 51
The concept of a port scanner 51
How to create an efficient port scanner 54
Summary 59
Chapter 3: Sniffing and Penetration Testing 60
Introducing a network sniffer 61
Passive sniffing 61
Active sniffing 61
Implementing a network sniffer using Python 61

||||||||||||||||||||
||||||||||||||||||||

Table of Contents

Format characters 63
Learning about packet crafting 73
Introducing ARP spoofing and implementing it using Python 74
The ARP request 74
The ARP reply 75
The ARP cache 75
Testing the security system using custom packet crafting 78
A half-open scan 79
The FIN scan 82
ACK flag scanning 83
Summary 85
Chapter 4: Network Attacks and Prevention 86
Technical requirements 86
DHCP starvation attack 87
The MAC flooding attack 93
How the switch uses the CAM tables 93
The MAC flood logic 94
Gateway disassociation by RAW socket 95
Torrent detection 96
Running the program in hidden mode 104
Summary 106
Chapter 5: Wireless Pentesting 107
Introduction to 802.11 frames 108
Wireless SSID finding and wireless traffic analysis with Python 110
Detecting clients of an AP 120
Wireless hidden SSID scanner 122
Wireless attacks 125
The deauthentication (deauth) attack 125
Detecting the deauth attack 128
Summary 131
Chapter 6: Honeypot – Building Traps for Attackers 132
Technical requirements 132
Fake ARP reply 133
Fake ping reply 135
Fake port-scanning reply 142
Fake OS-signature reply to nmap 145
Fake web server reply 146
Summary 149
Chapter 7: Foot Printing a Web Server and a Web Application 150
The concept of foot printing a web server 150
Introducing information gathering 151

[ ii ]

||||||||||||||||||||
||||||||||||||||||||

Table of Contents

Checking the HTTP header 155


Information gathering of a website from whois.domaintools.com 157
Email address gathering from a web page 159
Banner grabbing of a website 160
Hardening of a web server 161
Summary 162
Chapter 8: Client-Side and DDoS Attacks 163
Introducing client-side validation 163
Tampering with the client-side parameter with Python 164
Effects of parameter tampering on business 169
Introducing DoS and DDoS 172
Single IP, single ports 172
Single IP, multiple port 174
Multiple IP, multiple ports 176
Detection of DDoS 178
Summary 181
Chapter 9: Pentesting SQL and XSS 182
Introducing the SQL injection attack 183
Types of SQL injections 184
Simple SQL injection 184
Blind SQL injection 184
Understanding the SQL injection attack by a Python script 184
Learning about cross-site scripting 194
Persistent or stored XSS 195
Nonpersistent or reflected XSS 195
Summary 204
Other Books You May Enjoy 205
Index 208

[ iii ]

||||||||||||||||||||
||||||||||||||||||||

Preface
This book is a practical guide that shows you the advantages of using Python for
pentesting, with the help of detailed code examples. This book starts by exploring the
basics of networking with Python and then proceeds to network and wireless pentesting,
including information gathering and attacking. You will learn how to build honeypot traps.
Later on, we delve into hacking the application layer, where we start by gathering
information from a website, and then eventually move on to concepts related to website
hacking, such as parameter tampering, DDOS, XSS, and SQL injection.

Who this book is for


If you are a Python programmer, a security researcher, or a network admin who has basic
knowledge of Python programming and want to learn about penetration testing with the
help of Python, this book is ideal for you. Even if you are new to the field of ethical hacking,
this book can help you find the vulnerabilities in your system so that you are ready to
tackle any kind of attack or intrusion.

What this book covers


$IBQUFS, Python with Penetration Testing and Networking, goes through the prerequisites of
the following chapters. This chapter also discusses the socket and its methods. The server
socket's method defines how to create a simple server.

$IBQUFS, Scanning Pentesting, covers how to perform network scanning to gather


information on a network, host, and the services that are running on the hosts. You will see
a very fast and efficient IP scanner.

$IBQUFS, Sniffing and Penetration Testing, teaches how to perform active sniffing and how
to create a Transport layer sniffer. You will learn special kinds of scanning.

$IBQUFS, Network Attacks and Prevention, outlines different types of network attacks, such
as DHCP starvation and switch mac flooding. You will learn how to detect a torrent on the
client side.

||||||||||||||||||||
||||||||||||||||||||

Preface

$IBQUFS, Wireless Pentesting, goes through wireless frames and explains how to obtain
information such as SSID, BSSID, and the channel number from a wireless frame using a
Python script. In this type of attack, you will learn how to perform pentesting attacks on the
AP.

$IBQUFS, Honeypot ` Building Traps for Attackers, focuses on how to build a trap for
attackers. You will learn how to bulid code from TCP layer 2 to TCP layer 4.

$IBQUFS, Foot Printing a Web Server and a Web Application, dives into the importance of a
web server signature, email gathering, and why knowing the server signature is the first
step in hacking.

$IBQUFS, Client-Side and DDoS Attacks, explores client-side validation and how to bypass
client-side validation. This chapter covers the implantation of four types of DDoS attacks.

$IBQUFS, Pentesting SQL and XSS, discusses two major web attacks: SQL injection and
XSS. In SQL injection, you will learn how to find the admin login page using a Python
script.

To get the most out of this book


In order to understand the book reader must have the knowledge of Networking
fundamentals, basic knowledge of Linux OS, good knowledge of information security and
core Python.

In order to perform experiments or run the codes reader can use the virtual machine
(Vmware, virtual box). For Wireless pen-testing readers can use a wireless card TP-Link TL-
WN722N. Becuase TL-WN722N wireless card supports the Kali Linux in VMware.

Download the example code files


You can download the example code files for this book from your account at
XXXQBDLUQVCDPN. If you purchased this book elsewhere, you can visit
XXXQBDLUQVCDPNTVQQPSU and register to have the files emailed directly to you.

[2]

||||||||||||||||||||
||||||||||||||||||||

Preface

You can download the code files by following these steps:

1. Log in or register at XXXQBDLUQVCDPN.


2. Select the SUPPORT tab.
3. Click on Code Downloads & Errata.
4. Enter the name of the book in the Search box and follow the onscreen
instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the
latest version of:

WinRAR/7-Zip for Windows


Zipeg/iZip/UnRarX for Mac
7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at IUUQTHJUIVCDPN
1BDLU1VCMJTIJOH1ZUIPO1FOFUSBUJPO5FTUJOH&TTFOUJBMT4FDPOE&EJUJPO. In case
there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available
at IUUQTHJUIVCDPN1BDLU1VCMJTIJOH. Check them out!

Download the color images


We also provide a PDF file that has color images of the screenshots/diagrams used in this
book. You can download it here: IUUQXXXQBDLUQVCDPNTJUFTEFGBVMUGJMFT
EPXOMPBET1ZUIPO1FOFUSBUJPO5FTUJOH&TTFOUJBMT4FDPOE&EJUJPO@$PMPS*NBHFTQEG.

Code in Action
Visit the following link to check out videos of the code being run:
IUUQTHPPHMT#)7/%

[3]

||||||||||||||||||||
||||||||||||||||||||

Preface

Conventions used
There are a number of text conventions used throughout this book.

$PEF*O5FYU: Indicates code words in text, database table names, folder names, filenames,
file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an
example: "Mount the downloaded 8FC4UPSN ENH disk image file as another disk in
your system."

A block of code is set as follows:


JNQPSUPT
SFTQPOTFPTQPQFO QJOHO
GPSMJOFJOSFTQPOTFSFBEMJOFT 
QSJOUMJOF

When we wish to draw your attention to a particular part of a code block, the relevant lines
or items are set in bold:
s = socket.socket(socket.PF_PACKET, socket.SOCK_RAW,TPDLFUOUPIT Y
J

Any command-line input or output is written as follows:


python setup.py install

Bold: Indicates a new term, an important word, or words that you see onscreen. For
example, words in menus or dialog boxes appear in the text like this. Here is an example:
"Select System info from the Administration panel."

Warnings or important notes appear like this.

Tips and tricks appear like this.

[4]

||||||||||||||||||||
||||||||||||||||||||

Preface

Get in touch
Feedback from our readers is always welcome.

General feedback: Email GFFECBDL!QBDLUQVCDPN and mention the book title in the
subject of your message. If you have questions about any aspect of this book, please email
us at RVFTUJPOT!QBDLUQVCDPN.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you have found a mistake in this book, we would be grateful if you would
report this to us. Please visit XXXQBDLUQVCDPNTVCNJUFSSBUB, selecting your book,
clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we
would be grateful if you would provide us with the location address or website name.
Please contact us at DPQZSJHIU!QBDLUQVCDPN with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in
and you are interested in either writing or contributing to a book, please visit
BVUIPSTQBDLUQVCDPN.

Reviews
Please leave a review. Once you have read and used this book, why not leave a review on
the site that you purchased it from? Potential readers can then see and use your unbiased
opinion to make purchase decisions, we at Packt can understand what you think about our
products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit QBDLUQVCDPN.

[5]

||||||||||||||||||||
||||||||||||||||||||

1
Python with Penetration Testing
and Networking
Penetration (pen) tester and hacker are similar terms. The difference is that penetration
testers work for an organization to prevent hacking attempts, while hackers hack for any
purpose such as fame, selling vulnerability for money, or to exploit the vulnerability of
personal enmity.

Lots of well-trained hackers have got jobs in the information security field by hacking into a
system and then informing the victim of their security bug(s) so that they might be fixed.

A hacker is called a penetration tester when they work for an organization or company to
secure its system. A pentester performs hacking attempts to break into the network after
getting legal approval from the client and then presents a report of their findings. To
become an expert in pentesting, a person should have a deep knowledge of the concepts of
their technology. In this chapter, we will cover the following topics:

The scope of pentesting


The need for pentesting
Components to be tested
Qualities of a good pentester
Approaches to pentesting
Understanding the tests and tools you'll need
Network sockets
Server socket methods
Client socket methods
General socket methods
Practical examples of sockets
Socket exceptions
Useful socket methods

||||||||||||||||||||
Other documents randomly have
different content
Yo no sé por qué razón,
de mi tragedia, bufón,
te ríes... Mas tu eres vivo
por tu danzar sin motivo.
ELOGIOS

CXXXIX
A DON FRANCISCO GINER DE LOS RÍOS

Como se fué el maestro,


la luz de esta mañana
me dijo: Van tres días
que mi hermano Francisco no trabaja.
¿Murió?... Sólo sabemos
que se nos fué por una senda clara,
diciéndonos: Hacedme
un duelo de labores y esperanzas.
Sed buenos y no más, sed lo que he
sido
entre vosotros: alma.
Vivid, la vida sigue,
los muertos mueren y las sombras
pasan;
lleva quien deja y vive el que ha vivido.
¡Yunques, sonad; enmudeced,
campanas!

Y hacia otra luz más pura


partió el hermano de la luz del alba,
del sol de los talleres,
el viejo alegre de la vida santa.
...Oh, sí, llevad, amigos,
su cuerpo a la montaña,
a los azules montes
del ancho Guadarrama.
Allí hay barrancos hondos
de pinos verdes donde el viento canta.
Su corazón repose
bajo una encina casta,
en tierra de tomillos, donde juegan
mariposas doradas...
Allí el maestro un día
soñaba un nuevo florecer de España.
Baeza, 21 febrero, 1915.

CXL
AL JOVEN MEDITADOR
JOSÉ ORTEGA GASSET

A ti laurel y yedra
corónente, dilecto
de Sofía, arquitecto.
Cincel, martillo y piedra
y masones te sirvan; las montañas
de Guadarrama frío
te brinden el azul de sus entrañas,
meditador de otro Escorial sombrío;
y que Felipe austero,
al borde de su regia sepultura,
asome a ver la nueva arquitectura,
y bendiga la prole de Lutero.

CXLI
A XAVIER VALCARCE

...En el Intermedio de la primavera.


Valcarce, dulce amigo, si tuviera
la voz que tuve antaño, cantaría
el intermedio de tu primavera
—porque aprendiz he sido de ruiseñor un
día—,
y el rumor de tu huerto—entre las flores
el agua oculta corre, pasa y suena
por acequias, regatos y atanores—,
y el inquieto bullir de tu colmena,
y esa doliente juventud que tiene
ardores de faunalias,
y que pisando viene
la huella a mis sandalias.

Mas hoy... ¿será porque el enigma grave


me tentó en la desierta galería,
y abrí con una diminuta llave
el ventanal del fondo que da a la mar
sombría?
¿Será porque se ha ido
quien asentó mis pasos en la tierra,
y en este nuevo ejido
sin rubia mies, la soledad me aterra?

No sé, Valcarce, mas cantar no puedo;


se ha dormido la voz en mi garganta,
y tiene el corazón un salmo quedo.
Ya sólo reza el corazón, no canta.

Mas hoy, Valcarce, como un fraile viejo


puedo hacer confesión, que es dar consejo.

En este día claro, en que descansa


tu carne de quimeras y amoríos
—así en amplio silencio se remansa
el agua bullidora de los ríos—,
no guardes en tu cofre la galana
veste dominical, el limpio traje,
para llenar de lágrimas mañana
la mustia seda y el marchito encaje,
sino viste, Valcarce, dulce amigo,
gala de fiesta para andar contigo.

Y cíñete la espada rutilante,


y lleva tu armadura,
el peto de diamante
debajo de la blanca vestidura.

¡Quién sabe! Acaso tu domingo sea


la jornada guerrera y laboriosa,
el día del Señor, que no reposa,
el claro día en que el Señor pelea.

CXLII
MARIPOSA DE LA SIERRA
A Juan Ramón Jiménez,
por su libro Platero y yo.

¿No eres tú, mariposa,


el alma de estas sierras solitarias,
de sus barrancos hondos
y de sus cumbres agrias?
Para que tú nacieras,
con su varita mágica
a las tormentas de la piedra, un día,
mandó callar un hada,
y encadenó los montes,
para que tú volaras.
Anaranjada y negra,
morenita y dorada,
mariposa montés, sobre el romero
plegadas las alillas o, voltarias,
jugando con el sol, o sobre un rayo
de sol crucificadas.
¡Mariposa montés y campesina,
mariposa serrana,
nadie ha pintado tu color; tú vives
tu color y tus alas
en el aire, en el sol, sobre el
romero,
tan libre, tan salada!...
Que Juan Ramón Jiménez
pulse por ti su lira franciscana.
Sierra de Cazorla, 28 mayo, 1915.

CXLIII
DESDE MI RINCÓN
ELOGIOS

Al libro Castilla, del maestro Azorín,


con motivos del mismo.

Con este libro de melancolía,


toda Castilla a mi rincón me llega;
Castilla la gentil y la bravía,
la parda y la manchega.
¡Castilla, España de los largos ríos
que el mar no ha visto y corre hacia los
mares;
Castilla de los páramos sombríos,
Castilla de los negros encinares.
Labriegos transmarinos y pastores
trashumantes—arados y merinos—,
labriegos con talante de señores,
pastores del color de los caminos.
Castilla de grisientos peñascales,
pelados serrijones,
barbechos y trigales,
malezas y cambrones.
Castilla azafranada y polvorienta,
sin montes, de arreboles purpurinos,
Castilla visionaria y soñolienta
de llanuras, viñedos y molinos.
Castilla—hidalgos de semblante enjuto,
rudos jaques y orondos bodegueros—,
Castilla—trajinantes y arrieros
de ojos inquietos, de mirar astuto—,
mendigos rezadores,
y frailes pordioseros,
boteros, tejedores,
arcadores, perailes, chicarreros,
lechuzos y rufianes,
fulleros y truhanes,
caciques y tahures y logreros.
¡Oh, venta de los montes!—Fuencebada,
Fonfría, Oncala, Manzanal, Robledo.—
¡Mesón de los caminos y posada
de Esquivias, Salas, Almazán, Olmedo!
La ciudad diminuta y la campana
de las monjas que tañe, cristalina...
¡Oh, dueña doñeguil tan de mañana
y amor de Juan Ruiz a doña Endrina!
Las comadres—Gerarda y Celestina—
Los amantes—Fernando y Dorotea—
¡Oh casa, oh huerto, oh sala silenciosa!
¡Oh divino vasar en donde posa
sus dulces ojos verdes Melibea!
¡Oh jardín de cipreses y rosales,
donde Calisto ensimismado piensa,
que tornan con las nubes inmortales
las mismas olas de la mar inmensa!
¡Y este hoy que mira a ayer; y este mañana
que nacerá tan viejo!
¡Y esta esperanza vana
de romper el encanto del espejo!
¡Y esta agua amarga de la fuente ignota!
¡Y este filtrar la gran hipocondría
de España siglo a siglo y gota a gota!
¡Y este alma de Azorín... y este alma mía
que está viendo pasar, bajo la frente,
de una España la inmensa galería,
cual pasa del ahogado en la agonía
todo su ayer, vertiginosamente!
Basta. Azorín, yo creo
en el alma sutil de tu Castilla,
y en esa maravilla
de tu hombre triste del balcón, que veo
siempre añorar, la mano en la mejilla.
Contra el gesto del persa, que azotaba
la mar con su cadena;
contra la flecha que el tahur tiraba
al cielo, creo en la palabra buena.
Desde un pueblo que ayuna y se divierte,
ora y eructa, desde un pueblo impío
que juega al mus, de espaldas a la muerte,
creo en la libertad y en la esperanza,
y en una fe que nace
cuando se busca a Dios y no se alcanza,
y en el Dios que se lleva y que se hace.

ENVÍO

¡Oh, tú, Azorín que de la mar de


Ulises
viniste al ancho llano
en donde el gran Quijote, el buen
Quijano,
soñó con Esplandianes y Amadises;
buen Azorín, por adopción manchego,
que guardas tu alma ibera,
tu corazón de fuego
bajo el recio almidón de tu pechera
—un poco libertario
de cara a la doctrina,
¡admirable Azorín, el reaccionario
por asco de la greña jacobina!—;
pero tranquilo, varonil—la espada
ceñida a la cintura
y con santo rencor acicalada—,
sereno en el umbral de tu aventura!
¡Oh, tú, Azorín, escucha: España quiere
surgir, brotar, toda una España
empieza.
¿Y ha de helarse en la España que se
muere?
¿Ha de ahogarse en la España que
bosteza?
Para salvar la nueva epifanía
hay que acudir, ya es hora,
con el hacha y el fuego al nuevo día.
Oye cantar los gallos de la aurora.
Baeza, 1913.

CXLIV
A UNA ESPAÑA JOVEN

...Fué un tiempo de mentira, de infamia. A España toda,


la malherida España, de Carnaval vestida
nos la pusieron, pobre y escuálida y beoda
para que no acertara la mano con la herida.

Fué ayer; éramos casi adolescentes; era


con tiempo malo, encinta de lúgubres presagios,
cuando montar quisimos en pelo una quimera,
mientras la mar dormía ahita de naufragios.

Dejamos en el puerto la sórdida galera,


y en una nave de oro nos plugo navegar
hacia los altos mares, sin aguardar ribera,
lanzando velas y anclas y gobernalle al mar.

Ya entonces, por el fondo de nuestro sueño—herencia


de un siglo que vencido sin gloria se alejaba—
un alba entrar quería; con nuestra turbulencia
la luz de las divinas ideas batallaba.

Mas cada cual el rumbo siguió de su locura;


agilitó su brazo, acreditó su brío;
dejó como un espejo bruñida su armadura
y dijo: «El hoy es malo, pero el mañana... es mío».

Y es hoy aquel mañana de ayer... Y España toda


con sucios oropeles de Carnaval vestida
aún la tenemos: pobre y escuálida y beoda,
mas hoy de un vino malo: la sangre de su herida.

Tú, juventud más joven, si de más alta cumbre


la voluntad te llega, irás a tu aventura
despierta y transparente a la divina lumbre,
como el diamante clara, como el diamante pura.
Enero, 1915.

CXLV
ESPAÑA, EN PAZ

En mi rincón moruno, mientras repiquetea


el agua de la siembra bendita en mis cristales
yo pienso en la lejana Europa que pelea,
el fiero norte, envuelto en lluvias otoñales.

Donde combaten galos, ingleses y teutones,


allá, en la vieja Flandes y en una tarde fría,
sobre jinetes, carros, infantes y cañones
pondrá la lluvia el velo de su melancolía.
Envolverá la niebla el rojo expoliario
—sordina gris al férreo claror del campamento—,
las brumas de la Mancha caerán como un sudario
de la flamenca duna sobre el fangal sangriento.

Un César ha ordenado las tropas de Germania


contra el francés heroico y el triste moscovita,
y osó hostigar la rubia pantera de Britania.
Medio planeta en armas contra el teutón milita.

¡Señor! La guerra es mala y bárbara; la guerra,


odiada de las madres, las almas entigrece;
mientras la guerra pasa, ¿quién sembrará la
tierra?
¿Quién segará la espiga que junio amarillece?

Albión acecha y caza las quillas en los mares;


Germania arruina templos, moradas y talleres;
la guerra pone un soplo de hielo en los hogares,
y el hambre en los caminos, y el llanto en las
mujeres.

Es bárbara la guerra y torpe y regresiva;


¿por qué otra vez a Europa esta sangrienta racha
que siega el alma y esta locura acometiva?
¿por qué otra vez el hombre de sangre se
emborracha?

La guerra nos devuelve las podres y las pestes


del Ultramar cristiano; el vértigo de horrores
que trajo Atila a Europa con sus tartareas huestes;
las hordas mercenarias, los púnicos rencores;
la guerra nos devuelve los muertos milenarios
de cíclopes, centauros, Heracles y Teseos;
la guerra resucita los sueños cavernarios
del hombre con peludos mammuthes giganteos.
¿Y bien? El mundo en guerra y en paz España
sola.
¡Salud, oh buen Quijano! Por si ese gesto es tuyo,
yo te saludo. ¡Salve! Salud, paz española,
si no eres paz cobarde, sino desdén y orgullo.

Si eres desdén y orgullo, valor de ti, si bruñes


en esa paz, valiente, la enmohecida espada,
para tenerla limpia, sin tacha, cuando empuñes
el arma de tu vieja panoplia arrinconada;
si pules y acicalas tus hierros para, un día,
vestir de luz y, erguida: heme aquí, pues, España
en alma y cuerpo, toda, para una guerra mía,
heme aquí, pues, vestida para la propia hazaña,
decir para que diga quien oiga: es voz, no es eco,
el buen manchego habla palabras de cordura,
parece que el hidalgo amojamado y seco
entró en razón, y tiene espada a la cintura;
entonces, paz de España, yo te saludo.
Si eres
vergüenza humana de esos rencores cabezudos
con que se matan miles de avaros mercaderes,
sobre la madre tierra que los parió desnudos;
si sabes cómo Europa entera se anegaba
en una paz sin alma, en un afán sin vida,
y que una calentura cruel la aniquilaba,
que es hoy la fiebre de esta pelea fratricida;
si sabes que esos pueblos arrojan sus riquezas
al mar y al fuego—todos—para sentirse hermanos
un día ante el divino altar de la pobreza,
gabachos y tudescos, latinos y britanos,
entonces, paz de España, también yo te saludo,
y a ti, la España fuerte, si, en esta paz bendita,
en tu desdeño esculpes, como sobre un escudo,
dos ojos que avizoran y un ceño que medita.
Baeza, 10 de noviembre de 1914.
CXLVI
Flor de santidad.—Novela milenaria,
por don Ramón del Valle-Inclán.

Esta leyenda en sabio romance campesino,


ni arcaico ni moderno, por Valle-Inclán
escrita,
revela en los halagos de un viento
vespertino,
la santa flor de alma que nunca se marchita.

Es la leyenda campo y campo. Un


peregrino
que vuelve solitario de la sagrada tierra
donde Jesús morara, camina sin camino,
entre los agrios montes de la galaica sierra.

Hilando silenciosa, la rueca a la cintura,


Adega, en cuyos ojos la llama azul fulgura
de la piedad humilde, en el romero ha visto,
al declinar la tarde, la pálida figura,
la frente gloriosa de luz y la amargura
de amor que tuvo un día el Salvador Dom.
Cristo.

CXLVII
AL MAESTRO RUBÉN DARÍO

Este noble poeta que ha escuchado


los ecos de la tarde y los violines
del otoño en Verlaine, y que ha cortado
las rosas de Ronsard en los jardines
de Francia, hoy, peregrino
de un Ultramar de Sol, nos trae el oro
de su verbo divino.
¡Salterios del loor vibran en coro!
La nave bien guarnida,
con fuerte casco y acerada prora,
de viento y luz la blanca vela henchida
surca, pronta a arribar, la mar sonora;
y yo le grito: ¡Salve! a la bandera
flamígera que tiene
esta hermosa galera
que de una nueva España a España
viene.
1904.

CXLVIII
A LA MUERTE DE RUBÉN DARÍO

Si era toda en tu verso la armonía del mundo,


¿dónde fuiste, Darío, la armonía a buscar?
Jardinero de Hesperia, ruiseñor de los mares,
corazón asombrado de la música astral,
¿te ha llevado Dionysos de su mano al infierno
y con las nuevas rosas triunfante volverás?
¿Te han herido buscando la soñada florida,
la fuente de la eterna juventud, capitán?
Que en esta lengua madre la clara historia quede;
corazones de todas las Españas, llorad.
Rubén Darío ha muerto en Castilla del Oro,
esta nueva nos vino atravesando el mar.
Pongamos, españoles, en un severo mármol,
su nombre, flauta y lira, y una inscripción no más:
nadie esta lira taña, si no es el mismo Apolo,
nadie esta flauta suene si no es el mismo Pan.
1915 .

CXLIX
A NARCISO ALONSO CORTÉS,
POETA DE CASTILLA
Jam senior, sed cruda deo viridisque senecta.
Virgilio (Eneida).

Tus versos me han llegado a este rincón


manchego,
regio presente en arcas de rica taracea,
que guardan, entre ramos de castellano espliego,
narcisos de Citeres y lirios de Judea.

En tu árbol viejo anida un canto adolescente,


del ruiseñor de antaño la dulce melodía.
Poeta, que declaras arrugas en tu frente,
tu musa es la más noble: se llama Todavía.

El corazón del hombre con red sutil envuelve


el tiempo, como niebla de río una arboleda.
¡No mires: todo pasa; olvida: nada vuelve!
Y el corazón del hombre se angustia... ¡Nada
queda!

El tiempo rompe el hierro y gasta los marfiles.


Con limas y barrenas, buriles y tenazas,
el tiempo lanza obreros a trabajar febriles,
enanos con punzones y cíclopes con mazas.

El tiempo lame y roe y pule y mancha y muerde;


socava el alto muro, la piedra agujerea;
apaga la mejilla y abrasa la hoja verde;
sobre las frentes cava los surcos de la idea.

Pero el poeta afronta al tiempo inexorable,


como David al fiero gigante filisteo;
de su armadura busca la pieza vulnerable,
y quiere obrar la hazaña a que no osó Teseo.

Vencer al tiempo quiere. ¡Al tiempo! ¿Hay un


seguro
donde afincar la lucha? ¿Quién lanzará el venablo
que cace esa alimaña? ¿Se sabe de un conjuro
que ahuyente ese enemigo, como la cruz al
diablo?

El alma. El alma vence—¡la pobre cenicienta,


que en este siglo vano, cruel, empedernido,
por esos mundos vaga escuálida y hambrienta!—
al ángel de la muerte y al agua del olvido.

Su fortaleza opone al tiempo, como el puente


al ímpetu del río sus pétreos tajamares;
bajo ella el tiempo lleva bramando su torrente,
sus aguas cenagosas huyendo hacia los mares.

Poeta, el alma sólo es ancla en la ribera,


dardo cruel y doble escudo adamantino;
y en el diciembre helado, rosal de primavera;
y sol del caminante y sombra del camino.

Poeta, que declaras arrugas en tu frente,


tu noble verso sea más joven cada día;
que en tu árbol viejo suene el canto adolescente,
del ruiseñor eterno la dulce melodía.
Venta de Cárdenas, 24 octubre.

CXL
MIS POETAS

El primero es Gonzalo de Berceo llamado,


Gonzalo de Berceo, poeta y peregrino,
que yendo en romería acaeció en un prado,
y a quien los sabios pintan copiando un
pergamino.
Trovó a Santo Domingo, trovó a Santa María,
y a San Millán, y a San Lorenzo y Santa Oria,
y dijo: mi dictado non es de juglaría;
escrito lo tenemos; es verdadera historia.
Su verso es dulce y grave: monótonas hileras,
de chopos invernales en donde nada brilla;
renglones como surcos en pardas sementeras,
y lejos, las montañas azules de Castilla.
Él nos cuenta el repaire del romeo cansado;
leyendo en santorales y libros de oración,
copiando historias viejas, nos dice su dictado,
mientras le sale afuera la luz del corazón.

CLI
A DON MIGUEL DE UNAMUNO
Por su libro Vida de Don Quijote y Sancho.

Este donquijotesco
Don Miguel de Unamuno, fuerte vasco,
lleva el arnés grotesco
y el irrisorio casco
del buen manchego. Don Miguel
camina,
jinete de quimérica montura,
metiendo espuela de oro a su locura,
sin miedo de la lengua que malsina.

A un pueblo de arrieros,
lechuzos y tahures y logreros
dicta lecciones de Caballería.

Y el alma desalmada de su raza,


que bajo el golpe de su férrea maza
aún duerme, puede que despierte un
día.

Quiere enseñar el ceño de la duda


antes de que cabalgue, al caballero;
cual nuevo Hamlet, a mirar desnuda
cerca del corazón la hoja de acero.

Tiene el aliento de una estirpe fuerte


que soñó más allá de sus hogares,
y que el oro buscó tras de los mares.
Él señala la gloria tras la muerte.
Quiere ser fundador y dice: Creo,
Dios y adelante el ánima española...
Y es tan bueno y mejor que fué Loyola:
sabe a Jesús y escupe al fariseo.

CLII
A JUAN RAMÓN JIMÉNEZ
Por su libro Arias tristes.

Era una noche del mes


de mayo, azul y serena,
sobre el agudo ciprés
brillaba la luna llena,

iluminando la fuente
en donde el agua surtía,
sollozando intermitente.
Sólo la fuente se oía.

Después, se escuchó el
acento
de un oculto ruiseñor.
Quebró una racha de viento
la curva del surtidor.

Y una dulce melodía


vagó por todo el jardín:
entre los mirtos tañía
un músico su violín.
Era un acorde lamento
de juventud y de amor
para la luna y el viento,
el agua y el ruiseñor.

«El jardín tiene una fuente


y la fuente una quimera...».
Cantaba una voz doliente,
alma de la primavera.

Calló la voz y el violín


apagó su melodía.
Quedó la melancolía
vagando por el jardín.
Sólo la fuente se oía.
PUBLICACIONES DE LA
RESIDENCIA DE ESTUDIANTES

You might also like